-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed
Labels
plugin: unittestrelated to the unittest integration builtin pluginrelated to the unittest integration builtin plugintype: proposalproposal for a new feature, often to gather opinions or design the API around the new featureproposal for a new feature, often to gather opinions or design the API around the new feature
Milestone
Description
As discussed in #517.
Implement setup_*/teardown_*
using fixtures injected during collection.
During collection, TestCase
subclasses with a setup_
and/or teardown_
methods would have this fixture injected in the class:
@pytest.fixture(autouse=True)
def _xunit_setup_teardown_function(self):
if hasattr(self, 'setup_method'):
self.setup_method(self)
yield
if hasattr(self, 'teardown_method'):
self.teardown_method(self)
If neither method is present, then this fixture is not injected at all.
The same would be done for setUpClass
and setUpModule
.
This would solve the problems mentioned in #517 quite nicely.
As discussed, this change might introduce subtle errors so this might be better introduced with an option to revert to the old implementation.
This should no longer be a concern, because we will only handle pytest's methods this way.
EDIT: updated regarding #3094 (comment)
Metadata
Metadata
Assignees
Labels
plugin: unittestrelated to the unittest integration builtin pluginrelated to the unittest integration builtin plugintype: proposalproposal for a new feature, often to gather opinions or design the API around the new featureproposal for a new feature, often to gather opinions or design the API around the new feature