MOE icon indicating copy to clipboard operation
MOE copied to clipboard

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

Open suntzu86 opened this issue 10 years ago • 0 comments

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

suntzu86 avatar Oct 11 '14 00:10 suntzu86