Repository navigation
Open
Labels
topic: collectionrelated to the collection phase
Description
- a detailed description of the bug or problem you are having
- output of
pip listfrom the virtual environment you are using - pytest and operating system versions
- minimal example if possible
pip list
Package Version
---------- -------
attrs 22.1.0
iniconfig 1.1.1
packaging 21.3
pip 22.2.2
pluggy 1.0.0
py 1.11.0
pyparsing 3.0.9
pytest 7.1.3
setuptools 65.4.1
tomli 2.0.1
wheel 0.37.1
pytest skips everything after a left square bracket if provided with a path to a folder
~/workspace/pytest_test via 🐍 v3.10.6 (pytest_test)
❯ pytest
============================= test session starts ==============================
platform linux -- Python 3.10.6, pytest-7.1.3, pluggy-1.0.0
rootdir: /home/user/pytest_test
collected 2 items
simple/d1/test_public.py . [ 50%]
simple[hard]/d2/test_public.py . [100%]
============================== 2 passed in 0.01s ===============================
~/workspace/pytest_test via 🐍 v3.10.6 (pytest_test)
❯ pytest simple\[hard\]/
============================= test session starts ==============================
platform linux -- Python 3.10.6, pytest-7.1.3, pluggy-1.0.0
rootdir: /home/user/pytest_test
collected 1 item
simple/d1/test_public.py . [100%]
============================== 1 passed in 0.00s ===============================
~/workspace/pytest_test via 🐍 v3.10.6 (pytest_test)
❯ pytest 'simple[hard]/'
============================= test session starts ==============================
platform linux -- Python 3.10.6, pytest-7.1.3, pluggy-1.0.0
rootdir: /home/user/pytest_test
collected 1 item
simple/d1/test_public.py . [100%]
============================== 1 passed in 0.01s ===============================
~/workspace/pytest_test via 🐍 v3.10.6 (pytest_test)
❯ pytest "simple[hard]/"
============================= test session starts ==============================
platform linux -- Python 3.10.6, pytest-7.1.3, pluggy-1.0.0
rootdir: /home/user/pytest_test
collected 1 item
simple/d1/test_public.py . [100%]
============================== 1 passed in 0.01s ===============================
Check out the provided path in the second block and the path pytest tests
Reacted by aloha-yo, Konstantin Chernyshev, PazhyvilkaFiodar, Theodore Gerasimov and Mark Rothermel
Metadata
Metadata
Assignees
Labels
topic: collectionrelated to the collection phase
Activity
KingMichaelPark commentedon Oct 1, 2022
Have you tried putting the second command in " "
serjflint commentedon Oct 3, 2022
I tried now and updated the question
nnrepos commentedon Oct 14, 2022
@KingMichaelPark
here's the culprit: #9642
it seems like square brackets are considered part of pytest's syntax.
not sure if this is a bug or lack of documentation/warning then.
if you're interested in a fix, please let me know 😄
KingMichaelPark commentedon Oct 14, 2022
I think you should rename your directory 😉
nnrepos commentedon Oct 15, 2022
this is clearly not a sufficient solution. what about projects which use brackets in hundreds, thousands of directories?
something like this should, at the very least:
@nicoddemus, could you share your opinion please?
RonnyPfannschmidt commentedon Oct 15, 2022
Brackets are not supported as part of python module names, so unless extra contex is provided i consider it a no go
nnrepos commentedon Oct 15, 2022
according to the docs:
this paragraph implies that pytest also supports test directories, not just test modules.
regardless of that, shouldn't the code be able to identify and warn about these "illegal" directory names?
i think it would help users understand what is going on, and rename their directories.
RonnyPfannschmidt commentedon Oct 15, 2022
Some type of warning seems sensible
As far as I can tell in the last 15 years this is the first time that brackets in folder names came up as a request
KingMichaelPark commentedon Oct 15, 2022
Yeah I have never seen them, what's the use case for hundreds of thousands of directories with brackets in them (completely out of curiosity not a criticism)
nnrepos commentedon Oct 15, 2022
that's probably because the PR that broke them was pushed this february, and not everyone is using the latest pytest version.
if you would like me to add a warning in a new PR, please let me know.
thanks :)
nnrepos commentedon Oct 15, 2022
i honestly don't know, i just know it's possible 😅
RonnyPfannschmidt commentedon Oct 15, 2022
Oh yay, @asottile seems like a opportunity for pain was missed, seems like a preliminary look at the Filesystem is necessary after all 😭
asottile commentedon Oct 15, 2022
I'd rather just say "play stupid games win stupid prizes" -- putting square brackets in directory names imo clearly falls into that category
MaggiR commentedon Apr 24, 2025
Hi there!
I also just ran into that issue on my Windows machine. It took me 3 hours to determine that the root cause comes from pytest's inability to handle brackets in the path. I am using PyCharm, which passes absolute (full) paths to
pytestas arguments. As a consequence, if any of the test root's parent directories (even outside the project) have "[" or "]" in their name, pytest breaks.A simple warning would be very helpful here. 🙂