-
Notifications
You must be signed in to change notification settings - Fork 346
setUpClass is not called with either pytest>4.1.1 or pytest-django>3.4.6 #753
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 info. |
Would you know of an example unit test where one test_module imports the other, @blueyed ? |
Not from the top of my head, sorry - but there are not that many, and IIRC some unittest specific ones already. |
Maybe related: pytest-dev/pytest#5201 |
I'm trying to isolate it, sadly my setup is really complex. Another factor is that I use pytest-test-groups, possibly running the one test while the 2nd who imports it is not run, has an effect. |
That cannot be factored out / disabled? Then try to isolate it based on what it is doing. Yes, the problem appears to be non-obvious, otherwise it would likely have been fixed already - I was not able to reproduce it myself. If you cannot isolate it, I suggest debugging it with pdb / dumping |
I have spent many hours on debugging this and have finally at least some new evidence:
|
This helped me: Changing it to:
It makes absolutely no sense to me though oO. Sure hope this does not cost anyone else thaaat much time as it did me. I have this import concept all over the codebase, I don't understand why it would only happen there. |
Interesting!
|
Looks related to how pytest-django disables class methods btw (which is not done with newer pytest anymore): pytest-django/pytest_django/plugin.py Lines 380 to 394 in c1bdb8d
|
(Oh, thought this issue would be in pytest's repo.) |
It would make more sense there, though at the time of reporting I did not know better. |
Sure. I've looked quickly into reproducing this using https://github.com/blueyed/debug-pytest-unittest - it shows:
Not sure if that is what you are seeing etc - please either create a pytest test to reproduce your issue, or a patch for the above initial layout. |
Your repo is reproducing it nicely, the
|
This changes when inheriting from TestCase (to make them unittests actually): blueyed/debug-pytest-unittest@ae1f1d1 This then also runs 5 tests in total:
With
|
What happens here is that only "test_test.py" is collected, which has |
As for the "setUpClass is not called" issue: are you deriving from unittest.TestCase? |
The setUpClass is on a non-TestCase class. I expected it to be called non the less. Though I was so unfar unable to reproduce my exact scenario. :-/ |
This is similar to #710 and #624
These 2 combinations work for me on python2:
But I cannot run the 2 libraries together on their latest release as in one test method out of a test suite with more than 5000 unit tests it occurs that the
setUpClass
method for the one test is then not called. ThesetUpClass
is defined in a widely used mixin class (not inheriting from a TestClass base) and works everywhere else.It is really weird how two testcases seem to disturb one another but it does not make any sense to me:
Here a quick description of my scenario:
The text was updated successfully, but these errors were encountered: