Not recognizing paths with left square bracket
- [x] a detailed description of the bug or problem you are having
- [x] output of
pip listfrom the virtual environment you are using - [x] pytest and operating system versions
- [x] 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
Have you tried putting the second command in " "
Have you tried putting the second command in " "
I tried now and updated the question
@KingMichaelPark here's the culprit: https://github.com/pytest-dev/pytest/pull/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 😄
I think you should rename your directory 😉
I think you should rename your directory 😉
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:
- be well-documented
- raise a warning
@nicoddemus, could you share your opinion please?
Brackets are not supported as part of python module names, so unless extra contex is provided i consider it a no go
Brackets are not supported as part of python module names, so unless extra contex is provided i consider it a no go
according to the docs:
If no arguments are specified then collection starts from testpaths (if configured) or the current directory.
Alternatively, command line arguments can be used in any combination of directories, file names or node ids.
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.
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
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)
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
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 :)
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)
i honestly don't know, i just know it's possible 😅
Oh yay, @asottile seems like a opportunity for pain was missed, seems like a preliminary look at the Filesystem is necessary after all 😭
I'd rather just say "play stupid games win stupid prizes" -- putting square brackets in directory names imo clearly falls into that category
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 pytest as 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. 🙂