-
-
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
pytest 8.2.0 runs unittest.case.TestCase.__init__
during collecting phase in the same process
#12289
Comments
Is there a reason you are doing these things in |
Thanks for the response. It is true that we can move our logic from I just would like to confirm if this is an expected change of pytest 8.2.0 as it somehow seems to be a breaking change. If so, I guess it is worthing mentioning it in the change log https://docs.pytest.org/en/8.2.x/changelog.html. 😊 |
Its important to note that adding setup code to the constructor is always completely wrong for testcase subclasses So your code was always incorrect It simply didn't trigger before by accident |
Thanks a lot @RonnyPfannschmidt for the suggestion. I will make sure to move the logic into |
Yes it was an expected change though I didn't anticipate the issues and didn't consider it to be a breaking change (otherwise I wouldn't have done it in a minor release). I will definitely amend the release notes, I just haven't got to it yet. |
As unittest itself collects instances, |
Sorry to comment on a closed issue, but can you clarify this? Why is it wrong to add code to |
Unittest testcase instances are used for collection,also in unittest So running setup at that point in time is just incorrect |
Original issue: Azure/azure-cli#28848
By injecting
at https://github.com/Azure/azure-cli/blob/2750c65ea77638ecf699243555a5f2f7a1314ed4/src/azure-cli-testsdk/azure/cli/testsdk/base.py#L86, we can see different versions of pytest show different output:
With pytest 8.1.1:
With pytest 8.2.0:
This indicates pytest 8.2.0:
unittest.case.TestCase.__init__
forrunTest
and test methods that are not even invokedunittest.case.TestCase.__init__
during collecting phase in the same process, instead of forked processesunittest.case.TestCase.__init__
: https://github.com/Azure/azure-cli/blob/2750c65ea77638ecf699243555a5f2f7a1314ed4/src/azure-cli-core/azure/cli/core/mock.py#L32. This change makes environment variables in different test methods polluted.System info:
The text was updated successfully, but these errors were encountered: