question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`--deselect` doesn't work with absolute paths

See original GitHub issue
  • a detailed description of the bug or suggestion
  • output of pip list from the virtual environment you are using
  • pytest and operating system versions
  • minimal example if possible

I wanted to do something like pytest /path/to/project/tests/* --deselect /path/to/project/tests/test_needsToBeAvoided.py, but this didn’t work. Instead I had to do pytest /path/to/project/tests/* --deselect tests/test_needsToBeAvoided.py.

bstaletic@Gallifrey pytest % pip list
Package               Version
--------------------- ----------
attrs                 19.3.0
beautifulsoup4        4.8.2
certifi               2019.11.28
chardet               3.0.4
codecov               2.0.15
coverage              5.0.3
entrypoints           0.3
flake8                3.7.9
flake8-comprehensions 3.2.2
flake8-ycm            0.1.0
idna                  2.8
mccabe                0.6.1
more-itertools        8.2.0
packaging             20.1
pip                   20.0.2
pluggy                0.13.1
psutil                5.6.7
ptvsd                 4.3.2
py                    1.8.1
pycodestyle           2.5.0
pyflakes              2.1.1
PyHamcrest            2.0.0
pyparsing             2.4.6
pytest                5.3.5
pytest-cov            2.8.1
requests              2.22.0
setuptools            41.2.0
six                   1.14.0
soupsieve             1.9.5
urllib3               1.25.8
waitress              1.4.3
wcwidth               0.1.8
WebOb                 1.8.6
WebTest               2.0.34
bstaletic@Gallifrey pytest % python -c 'print(__import__("pytest").__version__)'
5.3.5
bstaletic@Gallifrey pytest % cat /etc/os-release
NAME="Artix Linux"
PRETTY_NAME="Artix Linux"
ID=artix
BUILD_ID=rolling
ANSI_COLOR="0;36"
HOME_URL="https://www.artixlinux.org/"
DOCUMENTATION_URL="https://wiki.artixlinux.org/"
SUPPORT_URL="https://forum.artixlinux.org/"
BUG_REPORT_URL="https://gitea.artixlinux.org/"
LOGO=artixlinux

Steps to repro:

  • mkdir ~/test
  • cd ~/test
  • echo 'def test_test():assert 1' > test_test.py
  • pytest ~/test/*_test.py --deselect test_test.py - this works. The report says “1 test deselected”.
  • pytest ~/test/*_test.py --deselect ~/test/test_test.py - this one doesn’t work. The test is being run.
  • pytest . --deselect ~/test/test_test.py - this one doesn’t work either. The test is being run.

Additional info:

I have encountered this with python 3.8.0 and 3.8.1. I have not tried any other version.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
bstaleticcommented, Feb 17, 2020

https://github.com/pytest-dev/pytest/blob/d79179a239ac89b318be47c99ff965376d177257/src/_pytest/main.py#L326-L341

That’s the function that takes --deselect-produced tuple and filters the tests. colitem.nodeid is something like (based off the example in OP) test_test.py::test_test, which isn’t the absolute path. Then pybind just says if nodeid.startswith(deselect_tuple), which clearly is false if --deselect contains an absolute path.

Note: nodeid doesn’t depend on current working directory.

However, this logic is fine. What should be changed is how nodeid gets assigned.

0reactions
fdav10commented, Jan 5, 2021

Two other issues that i’ve encountered with the --deselect argument are:

  1. Windows file paths involving backslashes aren’t converted to OS-agnostic nodeid-like paths Sorry, i’ve just read the thread properly and see that these are meant to be nodeids not paths
  2. The .startswith method used to match the deselect arguments against nodeids could be considered heavy-handed. In my use case I wanted to deselect a single test but the command ended up excluding multiple tests because they all started with a common string.

I’m happy to submit changes if these are thought to be bugs or otherwise undesirable.

Read more comments on GitHub >

github_iconTop Results From Across the Web

qmake: how to remove the dependency of absolute paths?
1 Answer 1 · you are right, hardcoded absolute paths in .pro file. And yes, I've tried to use . · So, you...
Read more >
Remove absolute paths from Rhapsody project - Forums - IBM
So two issues here: We want our code to use relative paths only - like any normal IDE : ) ... how can...
Read more >
linux - Why does getfacl remove the leading / from absolute ...
Since it is an absolute path, it seems slightly silly to strip it in the first place. In other distros (e.g. FreeBSD), this...
Read more >
pathlib — Object-oriented filesystem paths — Python 3.11.1 ...
Source code: Lib/pathlib.py This module offers classes representing filesystem paths with semantics appropriate for different operating systems.
Read more >
How to remove absolute paths in release binary - help
but when i changed my rustflages in cargo.toml,there are still have this problems. [build] rustflags = ["--remap-path-prefix", "$HOME=~ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found