-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Package scoped fixture will not execute teardown #8189
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
Just to make sure I understand, what you expect is that the first example have the same behavior as the second? You have 3 packages in play: |
@Zac-HD, so should I understand package fixture scope such as:
To be honest I am a little confuesd with your explanation because every other scope, except of maybe session has different behavior.
What would setup/teardown plan look like in this case? And to answer your question about my expectation - i kinda expect the same setup/teardown behavior to be applied to package level scopes, with exception that the boundary is on the package but not the module. |
And to proove my point further - another way to get expected (at least by me) behavior is:
|
@Zac-HD I think the best way to summarize is that currently package scope is related to "the package" when I expect it to be for "a package" |
Thanks for the details @hennadii-demchenko. I agree with your intuition here. I think the package scope and/or conftest handling is quite buggy. There's also some related discussion in #7777 (in the sense that it affects the behavior here). I'm marking this as a bug. Personally I do plan to dig into this more soon. |
@bluetech, thanks I'll keep an eye on the progress. Here's a quick tip on workaround for other people who might stumble upon this issue (it is easy although not very beatiful)
|
@bluetech any luck on getting back to this issue? |
to add extra context, each import of a fixture creates a new definition point, thus iporting the fixtures to closer file location points fixes the issues by creating new definitions its not clear to me whats the exact scoping of package scope fixtures, as they can have multiple points of reference its something tricky to get right |
Hey, it's been a while. Any chance this is gonna be fixed at all? |
I just met this exact issue. |
* Fixtures defined in a test package's conftest.py should not be session-scoped. Change the scope to "package". * Due to a bug in pytest [1] regarding when package-scoped fixtures are setup and teared down, move common package-scoped fixtures to pkgfixtures.py and import them explicitly in test packages' conftest.py or directly in test modules. * Add __init__.py to all test packages and to lib/, to make them proper python packages. [1] pytest-dev/pytest#8189
* Fixtures defined in a test package's conftest.py should not be session-scoped. Change the scope to "package". * Due to a bug in pytest [1] regarding when package-scoped fixtures are setup and teared down, move common package-scoped fixtures to pkgfixtures.py and import them explicitly in test packages' conftest.py or directly in test modules. * Add __init__.py to all test packages and to lib/, to make them proper python packages. [1] pytest-dev/pytest#8189
* Fixtures defined in a test package's conftest.py should not be session-scoped. Change the scope to "package". * Due to a bug in pytest [1] regarding when package-scoped fixtures are setup and teared down, move common package-scoped fixtures to pkgfixtures.py and import them explicitly in test packages' conftest.py or directly in test modules. * Add __init__.py to all test packages and to lib/, to make them proper python packages. [1] pytest-dev/pytest#8189
* Fixtures defined in a test package's conftest.py should not be session-scoped. Change the scope to "package". * Due to a bug in pytest [1] regarding when package-scoped fixtures are setup and teared down, move shared package-scoped fixtures to pkgfixtures.py and import them explicitly in the test packages' conftest.py. * Add __init__.py to all test packages and to lib/, to make them proper python packages. [1] pytest-dev/pytest#8189
* Fixtures defined in a test package's conftest.py should not be session-scoped. Change the scope to "package". * Due to a bug in pytest [1] regarding when package-scoped fixtures are setup and teared down, move shared package-scoped fixtures to pkgfixtures.py and import them explicitly in the test packages' conftest.py. * Add __init__.py to all test packages and to lib/, to make them proper python packages. [1] pytest-dev/pytest#8189 Signed-off-by: Samuel Verschelde <[email protected]>
* Fixtures defined in a test package's conftest.py should not be session-scoped. Change the scope to "package". * Due to a bug in pytest [1] regarding when package-scoped fixtures are setup and teared down, move shared package-scoped fixtures to pkgfixtures.py and import them explicitly in the test packages' conftest.py. * Add __init__.py to all test packages and to lib/, to make them proper python packages. [1] pytest-dev/pytest#8189 Signed-off-by: Samuel Verschelde <[email protected]>
* Fixtures defined in a test package's conftest.py should not be session-scoped. Change the scope to "package". * Due to a bug in pytest [1] regarding when package-scoped fixtures are setup and teared down, move shared package-scoped fixtures to pkgfixtures.py and import them explicitly in the test packages' conftest.py. * Add __init__.py to all test packages and to lib/, to make them proper python packages. [1] pytest-dev/pytest#8189 Signed-off-by: Samuel Verschelde <[email protected]>
* Fixtures defined in a test package's conftest.py should not be session-scoped. Change the scope to "package". * Due to a bug in pytest [1] regarding when package-scoped fixtures are setup and teared down, move shared package-scoped fixtures to pkgfixtures.py and import them explicitly in the test packages' conftest.py. * Add __init__.py to all test packages and to lib/, to make them proper python packages. [1] pytest-dev/pytest#8189 Signed-off-by: Samuel Verschelde <[email protected]>
* Fixtures defined in a test package's conftest.py should not be session-scoped. Change the scope to "package". * Due to a bug in pytest [1] regarding when package-scoped fixtures are setup and teared down, move shared package-scoped fixtures to pkgfixtures.py and import them explicitly in the test packages' conftest.py. * Add __init__.py to all test packages and to lib/, to make them proper python packages. [1] pytest-dev/pytest#8189 Signed-off-by: Samuel Verschelde <[email protected]>
* Fixtures defined in a test package's conftest.py should not be session-scoped. Change the scope to "package". * Due to a bug in pytest [1] regarding when package-scoped fixtures are setup and teared down, move shared package-scoped fixtures to pkgfixtures.py and import them explicitly in the test packages' conftest.py. * Add __init__.py to all test packages and to lib/, to make them proper python packages. [1] pytest-dev/pytest#8189 Signed-off-by: Samuel Verschelde <[email protected]>
+If uses package scope fixture with |
Marking as fixed in pytest 8.0.0 (#11646), let me know if not. |
The issue is still present. @bluetech what should I do with the new findings, should I open a new issue, or shall we reopen this one? Environment
Recreating original steps to reproduce
Result after adding additional
Result after adding additional
|
@hennadii-demchenko Apologies for the repetitiveness on my part (I think you probably answered this in one of the previous comments), but can you describe again what you expect to happen in each case above? |
@bluetech, sure, I expect that the package fixture has setup executed at the beginning of each package, and teardown at the end of each package.
|
Ok, I think I finally get where the confusion comes from. Consider following:
My assumptions are:
What I think is happening: |
@bluetech, I am pretty sure this issue will be easily forgotten since it is in a closed state. I understand it is better to open a new one and mention this, please confirm or deny. |
I'm seeing something similar, where we have a package fixture defined in conftest and three packages that each use the fixture. I expected the fixture to run three times, once for each package, but it is running only once per session. Maybe the same as #8712? |
There seems to be an obscure edge when the workaround is not properly applied - who knows, could it give some insights to help find a solution to the core issue... Let's say that the example above is modified so the test in the
The setup will appear to work as long as
... but as soon as for some reason bravo runs first,
|
pkgfixture stuff must *always* be used from conftest.py, or else strange problems appear because of the result shown in pytest-dev/pytest#8189 (comment) For this case it results in a test failure when test ordering changes, because of a safeguard added to the fixture. And "stop using a test parameter for sr_disk" commit does cause such a change in test ordering. Signed-off-by: Yann Dirson <[email protected]>
pkgfixture stuff must *always* be used from conftest.py, or else strange problems appear because of the result shown in pytest-dev/pytest#8189 (comment) For the host_with_saved_yum_state case it results in a test failure when test ordering changes, because of a safeguard added to the fixture. And "stop using a test parameter for sr_disk" commit does cause such a change in test ordering. Signed-off-by: Yann Dirson <[email protected]>
pkgfixture stuff must *always* be used from conftest.py, or else strange problems appear because of the result shown in pytest-dev/pytest#8189 (comment) Signed-off-by: Yann Dirson <[email protected]>
pkgfixture stuff must *always* be used from conftest.py, or else strange problems appear because of the result shown in pytest-dev/pytest#8189 (comment) For this case it results in a test failure when test ordering changes, because of a safeguard added to the fixture. And "stop using a test parameter for sr_disk" commit does cause such a change in test ordering. Signed-off-by: Yann Dirson <[email protected]>
pkgfixture stuff must *always* be used from conftest.py, or else strange problems appear because of the result shown in pytest-dev/pytest#8189 (comment) Signed-off-by: Yann Dirson <[email protected]>
I'm quite new on the subject, so I'll try to summarize what I understand of the issue.
If that understanding is correct, I expect we could solve the whole issue by letting the usage declaration of the fixture declare which package scope it refers to. And indeed, I see no reason not to extend this to all other scopes, so any given fixture could be used with any scope depending on the needs of the caller, rather than hardcoding a single possible scope for all callers (which can possibly cause headaches on a large and varied test repository) - after all the package-scoped fixtures to give us more flexibility, because we can choose to which level of the package hierarchy we bind them. Such a scope specification may not be possible to achieve on fixtures that get only declared as a parameter of the test function, but this would be easily dealt with by adding a decorator:
package scope would need something more to specify the package itself, which could be a scope of Does this make any sense to anyone else? |
I am experiencing a weird issue:
'package' scoped fixture will not execute teardown after last test in package is completed if afformentioned fixture is defined outside of package
Environment
Example to reproduce
Result
If I create two conftest files in each package with the package scoped fixture I intend to use then I can see it behaving as I was expecting.
Example:
The text was updated successfully, but these errors were encountered: