-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Wrong fixture/conftest being used #2836
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
Maybe you get more information if you run:
in your different environments and see if and how things behave differently? |
FWIW I also can't reproduce this. Just to make sure, the minimal example you posted here also fails on Jenkins? Besides @obestwalter's advice, I would also take a look at the environment variables. |
Thanks both. The minimal example given above fails on Jenkins but not elsewhere. I added
So that suggests it does recognise/collect both conftest modules, yet it's still using the fixture from the I'll also do a bit more digging into the env vars (Jenkins provides a lot of them, but a very quick skim doesn't show anything obviously askew, and all our other (quite a few of them) python/pytest jobs are working fine fortunately. |
So I've been doing a bit more digging, adding a bunch of debugging into pytest to see what's going on. I've found a couple of odd things, but I don't know if this is expected behaviour - it feels like it isn't. The crux of the error/odd behaviour seems to be is that at the point that the aa_foo test is collected. When However, when the It seemed weird to me that the second test function was being built with both fixtures being passed to it. Unless I misunderstand the scoping/visiblity rules of fixtures, in the setup we have, the contests of Original (
Renamed packages to
The key difference is the contents of the
E.g. in the case where the packages share this common root name, for some reason the fixtures from the first package become valid for use in the second package. Is this intended behaviour? It certainly seems to be odd. For example, it means that the following setup works, but I would expect it to fail: Example 2: integration_tests/init.py (empty)
integration_tests/aa/test_x.py
integration_tests/aa_foo/init.py (empty)
I would expect So I think the fact it works locally and not on Jenkins is just symptom. The real issue appears to be is that pytest allows test functions to use fixtures they shouldn't be able to see at all.
In the meantime I'm going to keep digging into how/why both fixtures get passed to the second function when the names share the short common root, in the hope it gets clearer if this is expected or not. |
I think I've found the cause of my woes, but I'll need someone to confirm if this is expected behaviour or a bug. I suspect (hope) it's the latter! The problem seems to come down to this method: https://github.com/pytest-dev/pytest/blob/master/_pytest/fixtures.py#L1133 which:
The way it decides if the node can see the fixture is a simple This means that in the case we have a test node like I'll make a minimal example repo to show the behaviour. |
Minimal example shown here: https://github.com/tom-dalton-fanduel/pytest-bug-demo/tree/master |
I've created PR #2862 with what seems to be a working fix for this issue... |
Great bughunting story, it was actually a joy following the narrative. :D |
Closing - Fixed by #2862 |
I discovered a weird issue when running int tests on our Jenkins node at work, which I cannot reproduce inside a dev/vagrant VM using the same versions. The behaviour described below is only on the Jenkins node, but I don't really know where to go next in working out why it's happening. The original errors were in a way more complex setup, but I've managed to reduce this to a fairly minimal example. I doubt anyone else will be able to repro this in isolation, but i'm hoping someone can help me with where to look next to work out what's going on.
Minimal example file structure:
integration_tests/init.py (empty)
integration_tests/aa/init.py (empty)
integration_tests/aa/conftest.py
integration_tests/aa/test_x.py
integration_tests/aa_foo/init.py (empty)
integration_tests/aa_foo/conftest.py
integration_tests/aa_foo/test_x.py
So we have 2 packages, each containing a conftest defining a fixture
url
and each containing a test.What we see is that when
aa_foo/test_x.py
executes, it's using the wrongurl
fixture - it's using the fixture fromaa
rather thanaa_foo
. From investigation, it seems to be somehow related toaa
andaa_foo
sharing a common root name (aa
). Longer versions of this name (originally these dirs were namedcreate
andcreate_with_stuff
shows the same issue. I shortened the name repeatedly, and aa is the sortest name that shows the issue - if I change the package names toa
anda_foo
, it starts working again.As said at the start, it works fine in a local development (vagrant) VM. Both cases (broken jenkins and working dev VM) are running Ubuntu 14.04 and python 3.5, and I've also created a new virtual env that only contains/installs py.test 3.2.3 to rule out other packages affecting this.
Are there any known bugs/issues in pytest that can cause this sort of behaviour? The original issue was found in a complex nest of parameterised fixtures defined at different levels, and I had originally assumed the bug was in that nest, but distilling it down to this simple example rules all the complexity out. It seems like pytest is simply using the wrong fixture.
Any help or guidance anyone can provide getting to the bottom of this would be very much appreciated!
The text was updated successfully, but these errors were encountered: