Make DBTestCase compatible with pytest #5691
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Background
I'm working towards introducing
pants
. Eventually I would like to use pants to run tests to take advantage of the fine-grained per-file caching of results that accounts for dependencies by python files (pants infers the deps by reading the python files). But, pants usespytest
to run tests notnosetest
.This is another of several PRs that improves our compatibility with pytest. Others include: #5686, #5689, #5690
Note: I do not have pytest support completely ironed out, but this is a step in that direction. Don't expect running all our tests with pytest to work yet.
Overview
DBTestCase was relying on some unittest/nosetest implmentation details that are not available when running under pytest.
The purpose of those adjustments was: Keep the DB after a test failure (do not drop it) to facilitate debugging.
However, pytest does not make results availble to fixtures. There are some complex workarounds, but there are issues with blindly copying the previous logic. For example, pytest can continue running tests after a failure or error unlike nosetest which we have configured to stop on failures. In order to safely skip dropping the DB, we need to make the DB available in a clean state after the test(s) using it. So, re-implementing this test feature requires something that renames a DB to preserve data for debugging, so that subsequent tests have a clean DB to work with.
I left a
TODO
note about this for whoever ends up trying to implement this. For now, this just avoids accessing attributes on an TestResult object that pytest does not provide.