Skip to content
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

Not recognizing paths with left square bracket #10329

Open
4 tasks done
serjflint opened this issue Oct 1, 2022 · 13 comments
Open
4 tasks done

Not recognizing paths with left square bracket #10329

serjflint opened this issue Oct 1, 2022 · 13 comments
Labels
topic: collection related to the collection phase

Comments

@serjflint
Copy link

serjflint commented Oct 1, 2022

  • a detailed description of the bug or problem you are having
  • output of pip list from 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

@KingMichaelPark
Copy link

Have you tried putting the second command in " "

@Zac-HD Zac-HD added the topic: collection related to the collection phase label Oct 3, 2022
@serjflint
Copy link
Author

Have you tried putting the second command in " "

I tried now and updated the question

@nnrepos
Copy link
Contributor

nnrepos commented 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
Copy link

I think you should rename your directory 😉

@nnrepos
Copy link
Contributor

nnrepos commented Oct 15, 2022

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?

@RonnyPfannschmidt
Copy link
Member

Brackets are not supported as part of python module names, so unless extra contex is provided i consider it a no go

@nnrepos
Copy link
Contributor

nnrepos commented 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

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.

@RonnyPfannschmidt
Copy link
Member

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
Copy link

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
Copy link
Contributor

nnrepos commented 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

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
Copy link
Contributor

nnrepos commented 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)

i honestly don't know, i just know it's possible 😅

@RonnyPfannschmidt
Copy link
Member

Oh yay, @asottile seems like a opportunity for pain was missed, seems like a preliminary look at the Filesystem is necessary after all 😭

@asottile
Copy link
Member

I'd rather just say "play stupid games win stupid prizes" -- putting square brackets in directory names imo clearly falls into that category

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: collection related to the collection phase
Projects
None yet
Development

No branches or pull requests

6 participants