-
-
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
non-parameterized fixtures not torn down after last use #393
Comments
Original comment by Laurence Rowe (BitBucket: lrowe, GitHub: lrowe): Here's an example demonstrating the current behaviour. The fixtures conftest.py:
test_a.py:
test_b.py:
output of
What I'd like to see instead is:
This time only fixtures that are required for the current test are active and the tests have been re-ordered to be grouped by fixture usage to reduce the number of times fixtures need to be set up. (This would be equivalent to the behaviour of zope.testrunner's layers: https://pypi.python.org/pypi/zope.testrunner#layers) It might be too much of a change for other users to make active fixture minimisation the default (I would have found it less surprising, but then I was used to the zope.testrunner behaviour before.) Perhaps the ability to mark certain fixtures as being impure or effecting particular global state:
That way no two fixtures marked as effecting the same global state would be active concurently. |
Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42): Thanks for the example! I'd think you may also mark "data1" and "data2" to never be "active" at the same time. This would also make it an error to try to use data1 and data2 in the same test. I guess your notation achieves this more indirectly. I am not sure ATM how easy this is to implement, to be honest. |
Original comment by BitBucket: vaab, GitHub: vaab: Hi, coming also from zope.testrunner, and having the same issue. I can give a real world scenario : I have an application that supports addons. These tests are not located anywhere specific, for instance some addon could add some tests to another addon. There are no relation to python packages nor directory. So tests requiring the same addon fixture could be anywhere in the collected test of pytest. Following the documentation, I would expect:
But, this is what we currently get:
In my scenario, actual tests gets an environment they didn't ask for: For instance, the tests on 'addon B' will have the fixture 'addon A installed' active and they didn't ask for it. This will change and depend if I select test A to be run, or the order of the tests changes. More over, I could really want to make some test with both addon fixtures, and this last case should definitively be different. In the current implementation: you don't garantee that only the fixtures asked for are actually setup before running the test... other unrelated fixture could or couldn't be setup depending on test order, test selection ... isn't that a flaw ? Why not simply teardown a fixture once there are no more tests that will use it ? I don't think we need to "mark" incompatible fixture. Just ensuring that a test gets only the fixture it asked for seems saner to me. I'm probably missing some obvious information why it wasn't already implemented in pytest, and I apologies in advance for my blindness. I would be very happy to get the correct pointer to understand the current choices on that topic. Thanks ! |
Hi, I think this is related to #687, and I'm also interested in having the fixture (at least module scope) being torn down when they're not needed any more. |
This behaviour also surprised me. As I'd hoped to use this to address out of memory issues. We have some tests across multiple modules that require pyspark which spins up an entire Java VM. We also have some other unrelated tests that are memory heavy. I had thought from "pytest minimizes the number of active fixtures during test runs" in the documentation that a session fixture might fix this. I could address this with a module scoped fixture but then I'd be restarting that Java VM for each of the modules that does spark stuff, which is not ideal. |
closing this for now as the design of the current scoping system makes it impossible to afely do an da major refactor that didnt manifest in the last decade precludes it |
Originally reported by: Laurence Rowe (BitBucket: lrowe, GitHub: lrowe)
In the documentation at http://pytest.org/latest/fixture.html#automatic-grouping-of-tests-by-fixture-instances it mentions that:
However standard (non-parameterized) fixtures are not torn down after last use and persist until the end of the session / module which prevents one from writing alternative fixtures setting up different global states for use in different tests.
It would be great if there was a way to mark certain fixtures as being mutually exclusive (i.e. setting up the same global state object) so that alternative global states could be setup for different tests.
The text was updated successfully, but these errors were encountered: