Yelp / MOE

A global, black box optimization engine for real world metric optimization.
Other
1.31k stars 139 forks source link

[Python] improve pytest fixture use, e.g., scoping #411

Open suntzu86 opened 9 years ago

suntzu86 commented 9 years ago

pytest fixtures let us do a lot more than we could with the old teardown/setup style. We should stop emulating testify/xUnit and start using pytest: http://pytest.org/latest/fixture.html http://pytest.org/latest/builtin.html#fixtures-and-requests http://pythontesting.net/framework/pytest/pytest-fixtures-nuts-bolts/

The current implementation just translates testify's setup and class_setup functionality into pytest.fixture. But fixtures are a lot more powerful. We can...

  1. use scope: only construct expensive things like GaussianProcessTestCase once
  2. modularity and calling fixtures from other fixtures: simplify ``TestCase* hierarchies which were poor attempts to build fixtures inside of testify. combines with #409
  3. more granularity, able to specify fixtures per test and combine them easily
  4. return resources directly
  5. and more!

edit: let's also think hard about "autouse". autouse makes it so that any test that can see the fixture will use the fixture. I feel like with stuff like this, you'd much rather opt-in explicitly than have fixtures running everywhere. see: http://pytest.org/latest/fixture.html#autouse-fixtures-xunit-setup-on-steroids