-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Documentation: setup
and teardown
aren't mentioned
#9549
Comments
Hi @alfredodeza, Fair question.
For example, the example below works when executing class Test:
def setup(self):
self.x = 1
def test_foo(self):
assert self.x == 1 So this is a nose-idiom, not a pytest-idiom. Perhaps we need to document |
Good point @nicoddemus . I forgot to mention I also went through the Thanks for pointing out that these aren't pytest-native methods and are meant to support the other test framework (TIL!) In any case, I'm happy to provide a PR that explains this better, but would like to have something to correlate to Nose (couldn't find a reference) |
Not sure either, I'm not familiar with nose's docs myself, but it certainly is supported: # test_foo.py
class Test:
def setup(self):
self.x = 1
def test_foo(self):
assert self.x == 1
|
i just came across this in a potentially even more surprising scenario. my test module had a (top level) import of a function that happened to be called (extra context: this is using django and pytest-django, that setup function happens to use the db. the test that usually calls it is marked with because the |
update: git bisect points to 89f0b5b. |
While browsing the current release docs on "xunit-style" support, specifically the usage of setup and tearing down (cleanup) of tests, I was surprised not to see
setup()
andteardown()
mentioned. Instead, the documentation points out that for methods, one must usesetup_method()
andteardown_method()
.I've always used
setup()
andteardown()
methods for setting up and cleaning up before and after each test method in a class for production code as well as teaching Pytest.Are those methods deprecated and shouldn't be used? Supported by mistake? Or is it an omission in the docs? Either way the docs need to be rectified for correctness. I'm happy to provide a PR with the right path.
The text was updated successfully, but these errors were encountered: