-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Closed
Description
- a detailed description of the bug or problem you are havingoutput of
pip list
from the virtual environment you are using- NB: Before and after failing CI runs: https://www.diffchecker.com/SReU8wCR/
To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.pytest and operating system versions- 8.3.1, multiple different GitHub Actions runners (
windows-2019
,ubuntu-2022
, etc.)
To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.minimal example if possibleTo pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.
We have the following setup.cfg
file:
[tool:pytest]
addopts = --verbose --show-capture=stderr --tb=native
python_files = testing/**/test_*.py
# NB: norecursedirs is *not* set
When running pytest
(with no additional options) in the root of our repository, we see the following behavior:
pytest==8.2.2
: Only our tests are collected.pytest==8.3.1
: Our tests and the tests of our dependencies are collected, leading to many errors.collecting ... collected 367457 items / 408 errors / 100 skipped
(Woof!)
Changing our setup.cfg
to the following didn't fix the problem either:
[tool:pytest]
addopts = --verbose --show-capture=stderr --tb=native
testpaths = testing
python_files = test_*.py
The fix I used was adding norecursedirs = {name_of_venv}
Since this involves collection in virtual environments, the reason for the regression might be related to changes in:
Notably, we use a conda
env with pip
packages installed inside, which may subvert the expectations of the changes in the above PR.
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
[-]`pytest==8.3.1` collects tests from Python dependencies within venvs (regression from `8.2.2`)[/-][+]`pytest==8.3.1` collects tests from Python dependencies within venvs unless `norecursedirs` is set (regression from `8.2.2`)[/+]norecursedirs
insetup.cfg
to avoid pytest collecting tests from our dependencies within ourvenv
spinalcordtoolbox/spinalcordtoolbox#4571Set `norecursedirs` in `setup.cfg` to avoid pytest collecting tests f…
bluetech commentedon Jul 22, 2024
Does the venv directory contain a
pyvenv.cfg
file?joshuacwnewton commentedon Jul 22, 2024
Yes!
bluetech commentedon Jul 22, 2024
Interesting. Any chance you can poke the
_in_venv
function https://github.com/pytest-dev/pytest/blob/8.3.1/src/_pytest/main.py#L370 to see why it fails for this path./python/envs/venv_sct/
?joshuacwnewton commentedon Jul 22, 2024
In a Python console:
Exploring more on my end too... 🤔
joshuacwnewton commentedon Jul 22, 2024
Hmm. On my local Linux machine, I get fewer errors. Windows specifically reports many more errors... so I might have to test on a Windows machine. See:
pytest
-related import errors during the collection stage spinalcordtoolbox/spinalcordtoolbox#4570Hemario commentedon Jul 23, 2024
Just chiming in. We run automated tested in a docker container and on that container, we load the conda prefix inside the project folder. We could probably have done this better, but it was working for us in the past.
/projects/projectX: the git repository location
/projects/projectX/conda: the conda prefix
Since version 8.3.1 we notice the same issue as described above. Tests from included packages are being discovered.
With pytest 8.2.2: collected 190 items / 1 deselected / 189 selected
With pytest 8.3.1: collected 85611 items / 157 errors / 1 deselected / 29 skipped / 85610 selected
We solved it by adding to pytest.ini
RonnyPfannschmidt commentedon Jul 23, 2024
it seems like checking only for modern venv left us wanting for conda - is there a similar easy check we could do for conda prefixes/envs -- i'll reach out to conda on fosstodon to get input on fixing this, we might have to undo the steamlining for now
[-]`pytest==8.3.1` collects tests from Python dependencies within venvs unless `norecursedirs` is set (regression from `8.2.2`)[/-][+]`pytest==8.3.1` collects tests from Python dependencies within `conda` environments (regression from `8.2.2`)[/+]jezdez commentedon Jul 23, 2024
For the record, I'm responding to @RonnyPfannschmidt reaching out on Mastodon (https://fosstodon.org/@ossronny/112837662322781627), we'll take a look at this ASAP.
jezdez commentedon Jul 23, 2024
@RonnyPfannschmidt Can you provide more details other than what was said here, which feature was added in 8.3.1 that triggered this?
jezdez commentedon Jul 23, 2024
I've filed conda/conda#14069
jezdez commentedon Jul 23, 2024
Looks like #12544/#12545 is the culprit that reduces virtualenv detection to look for
pyvenv.cfg
only and effectively removes conda environment detection.Given that we can't easily retrofit existing conda environments out there, and a significant number of users are using
pytest
within conda environments, I'd appreciate it, if you could revert the patch, or at least retrofit it with the previous detection mechanism.RonnyPfannschmidt commentedon Jul 23, 2024
as per #12545 (comment) - i'd slightly prefer adding explicit conda detection over reverting - in case thats not easy/feasible quickly we go with a revert
RonnyPfannschmidt commentedon Jul 23, 2024
@jezdez so the key question - is there a easy foolproof way to check for conda explicitly - even if a
pyvenv.cfg
was not yet retrofittedjezdez commentedon Jul 23, 2024
The best course of action would probably be checking for
path.joinpath("conda-meta", "history").is_file()
for now, as that's required to exist for conda envs to use the conda environment revision system (conda list --revisions
andconda install --revision REV
).RonnyPfannschmidt commentedon Jul 23, 2024
working on a bugfix now, venv detection will be expanded to ("conda-meta", "history")
explicitly detect conda envs - fixes pytest-dev#12652
explicitly detect conda envs - fixes pytest-dev#12652
Merge pull request #12657 from pytest-dev/patchback/backports/8.3.x/6…
debugpy.debugJustMyCode
insettings.json
doesn't apply to thedebug-test
purpose
inlaunch.json
microsoft/vscode-python-debugger#335RonnyPfannschmidt commentedon Jul 25, 2024
released