-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Docs: Add details on possible leakage when using test classes #8252
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
Comments
Thanks for the suggestion!
Not sure I understand, that sentence is accurate to me. What do you have in mind? Also, would you consider writing a PR with what you believe would be a better guidance? We can then discuss this over a more concrete suggestion. 👍 |
Hi again. I'll have to apologize. I believe I confused class attributes with instance attributes, but should have known better. To elaborate, given a class like this: class TestMyClass:
my_attribute = SomeObject()
def setup_method(self):
self.my_other_attribute = SomeObject()
def test_a(self):
self.my_attribute.increment()
self.my_other_attribute.increment()
assert self.my_attribute() == self.my_other_attribute()
def test_b(self):
assert self.my_attribute() == self.my_other_attribute() under the assumption that As a result, you are 100% correct, the original documentation is accurate. Nevertheless one might add another hint for people like me. Perhaps something along the lines of:
|
No worries.
I'm OK with adding that note, would you like to contribute a PR with that? |
solves [8252](pytest-dev#8252)
Hi! I just ran into a similar problem to this one, where the result of tests depended on the order in which they were run. The root cause of this was that I defined attributes on the
TestClass
's level and mocked methods of these attributes. Eventually I found out that this could be overcome by using thesetup_method
of the class instead of class attributes. When going over the docs for grouping multiple tests in a class, I found no hint of this possible problem. Others might run into this problem as well and there already exists proper documentation of the solution here.May I suggest to replace the following sentences by a more accurate documentation? As there seem to be cases in which it is not 100% true, I find it possibly misleading (e.g. when combining pytest with mocking).
The text was updated successfully, but these errors were encountered: