-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Possible Bug in package scoped fixture teardown #4684
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
Unless, of course, my ordering assumptions are wrong. |
I don't know enough about fixtures to comment on the details, but you'd probably have better luck opening a pull request to propose changes. |
I shouldn't propose changes if the behaviour is what's expected, hence this pre-PR issue. |
Also, the above is just proposing a test shiv will fail, the fix is yet unknown. Don't even know if its desirable, if it is, this shouldn't have been closed. |
@s0undt3ch indeed looks like a bug, thanks for reporting it. |
I have the similar issue with "scope=package" when I want to group my test in a few sub-folders using one common conftest.
But at the same time the issue is not reproduced if there are no any nested tests in sub-packages like:
Now the order of fixtures execution is correct. I hope this info will be useful. |
I've been trying to address this issue. Which at least suggests how fixture teardown should be, ie, if not going to be used anymore, finalize it. Now, it breaks a lot of tests, even an acceptance test which just passes a tempdir to Would you agree that this fixture termination is the desired one but we've just been relying on deferred termination routines? Is this the wrong approach? |
Hi there I ran into this issue today. Thanks @RomanPylypenkoDevPro for explaining it. I guess the workaround for now is to avoid sub packages? |
Is it fair to say that if we are in package scope A and we enter package B which is a sub-package of A, any fixtures in the package A scope should not be teardown? I still think it's useful to teardown fixtures when they are no longer going to be used, but this "usage tracking" might not be preferable. |
New diff for tests against current master https://gist.github.com/s0undt3ch/021d86c62ab2c4824abea23b1cc9c5f5#file-fixtures-diff-L16
|
Guess the bug is still there. Env:
Folder structure:
Content of import asyncio
from collections.abc import AsyncIterator, Iterable
import pytest
@pytest.fixture(scope="package")
def event_loop() -> Iterable[asyncio.AbstractEventLoop]:
policy = asyncio.get_event_loop_policy()
loop = policy.new_event_loop()
yield loop
loop.close()
@pytest.fixture(scope="package")
async def async_package_fixture() -> AsyncIterator[None]:
yield Content of async def test_inner(async_package_fixture: None) -> None:
pass Content of async def test_outer() -> None:
pass Output of
Guess the main info is the following:
There's no teardown for package-scoped event_loop before setup/teardown of function-scoped event_loop. The consequence of it is an attempt to close closed event_loop. |
Currently we have the issue that multi level package scope is practically undefined and not safely fixable without major reworks |
I haven't tested the exact scenarios, but I believe this should be fixed with #11646. Please test |
Confirm that my example is resolved in 8.0.0rc1 |
Please consider the following diff against PyTest 4.1:
The difference in the tests is that on
test_multiple_packages
, there's no fixture reuse/extend, while ontest_multiple_packages_inherit
I "extend" thefix
fixture.On
test_multiple_packages_inherit
, at teardown, I expect sub_1_2 to cleanup first, then sub_1, but the test fails at sub_2 because it still contains the item added in sub_1(which didn't ran it's teardown code yet?The text was updated successfully, but these errors were encountered: