-
Notifications
You must be signed in to change notification settings - Fork 22
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
tests work in 6.2.5 but fail in 7.x.x #67
Comments
* Make sure that tests run via make python-test are all run with '--forked' argument. * See pytest-dev/pytest-forked#67 and pytest-dev/pytest#9621 for details
* Make sure that tests run via make python-test are all run with '--forked' argument. * See pytest-dev/pytest-forked#67 and pytest-dev/pytest#9621 for details
Seeing the same failure in aiohttp-devtools: aio-libs/aiohttp-devtools#489 |
@Dreamsorcerer I tried debugging this several times, but I lack the knowledge of the pytest internals to get to the bottom of it. So if you ever end up finding out the root cause, make sure to send a PR. |
this is most likely related to the fact that pytest-forked does crazy things to setupstate in a forked process since pytest internals are msote strict now it trips |
It'd be great to solve this as the pytest 7 is spreading. |
The errors I have might be different from the original report. I'm using pytest 7.2.0 and the result is:
|
@frenzymadness yes, that is different. In your case, it's this the test itself that doesn't match the expected output. |
The error that @frenzymadness noted should be fixed by #74. |
Hi, is there any plan to address this? As pytest 7.x.x usage is spreading this could become a more serious blocker down the road. |
currently im not aware of anyone wanting to pick this up |
pity, but thanks for the quick reply. Just want to add that in my case I have the AssertionError even for pytest 6.x.x (I tested several versions). The only difference is the absence of the exception message:
My current workaround is to revert to pytest 5.x.x, then tests pass... but it clearly cannot be a long-term solution, eventually we will have to move to newer pytest versions. Unfortunately I need pytest-forked for a few tests that should be run in a subprocess. |
I tried digging into this, and there is some progress. tl;dr: as a workaround, ensure you don't have modules/classes that mix forked and non-forked tests so that a forked test is the last to run. Isolate forked tests into separate module(s), move non-forked tests below forked ones, or just add an empty non-forked test after forked ones. That's it. So, the crux of the issue is that pytest started doing more validation of its internal state ( Compare pytest7 and pytest6 — logic is roughly the same, but with a bunch of sanity checks on top. This is good. What I put together a repro case walking through the issue. Quick recap: We have two modules and three tests total (four if we include a workaround):
The way teardown works is pytest takes "current" and "next" tests, and tears down the stack (which should match collector list for the "current" test) until it matches collector list for the "next" test. What this means for us is that as long as both tests are in the same module, that module remains on the stack. Once "next" test comes from another module, module for "current" is removed from the stack. Now, back to the repro case:
From this description we can also notice ways to work around the issue:
I tried a couple of approaches to fixing the state from within the library, but my pytest knowledge is lacking. So far the only potential approach I see is moving setup/teardown back into main process, which is a breaking change for those who relied on forks for resource/state (mis)management. I'll play some more with it, and if it works with some existing codebases I'll open a PR. |
|
Fix: getsentry#3035 Rearrange test items so that forked tests come before normal tests within their respective modules. Swap the last forked test with the last normal test if necessary. Workaround to unpin pytest. See: pytest-dev/pytest#9621, pytest-dev/pytest-forked#67, and specifically: pytest-dev/pytest-forked#67 (comment)
Fix: getsentry#3035 Rearrange test items so that forked tests come before normal tests within their respective modules. Swap the last forked test with the last normal test if necessary. Workaround to unpin pytest. See: pytest-dev/pytest#9621, pytest-dev/pytest-forked#67, and specifically: pytest-dev/pytest-forked#67 (comment)
Remove Pytest pin. This requires ensuring that any test modules which contain both forked and non-forked tests do not have a forked test as the last test in the module. See [here](pytest-dev/pytest-forked#67 (comment)). Closes #3035
Remove Pytest pin. This requires ensuring that any test modules which contain both forked and non-forked tests do not have a forked test as the last test in the module. See [here](pytest-dev/pytest-forked#67 (comment)). Closes #3035
Remove Pytest pin. This requires ensuring that any test modules which contain both forked and non-forked tests do not have a forked test as the last test in the module. See [here](pytest-dev/pytest-forked#67 (comment)). Closes #3035
Remove Pytest pin. This requires ensuring that any test modules which contain both forked and non-forked tests do not have a forked test as the last test in the module. See [here](pytest-dev/pytest-forked#67 (comment)). Closes #3035
tests marked with
@pytest.mark.forked
that work in
pytest
v. 6.2.5 will fail inpytest
v. 7.x.x with message:see: pytest-dev/pytest#9621
The text was updated successfully, but these errors were encountered: