-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Pytest trying to check if custom argument is a file crashes due to filename being too long #10169
Comments
Thanks for the report @jdckmz! |
From what I can tell, if we have got to this point there is no pluginmanager has picked up the command line arg, so is there really anything we can do? |
The args that I've added aren't part of a plugin but are part of pytest itself as I understand, documented here: def pytest_addoption(parser):
"""pytest hook to add command line options."""
group = parser.getgroup("Canvas Test Options")
group.addoption(
"--xxxxx_flags",
default=None,
help="Extra flags to pass to the launched process.",
) |
Ok after some investigation, you need to make |
I am seeing the same thing, there is even a comment in _set_initial_conftests that suggests this could be an issue:
Maybe there should be a try/except around the exists call? Or alternatively run this logic after trying to parse the arguments? |
Due to pytest-dev/pytest#10169 we can't have command line flags with long names since pytest will check if any argument is a valid path (even if it's registered as a command line option) and Path.exist() may raise an exception which kills the entire pytest process. Work around this by splitting the single list of unsupported options into one option per feature.
@arichardson funny you posted this today, as I did a workaround for that just yesterday in https://github.com/pytest-dev/pytest/pull/10988/files#diff-df52f8f6a3544754cc8ebdf903594738e68a18dc9ac3c959f646cf4705a9afed. Seems however we should remove that guard against Python 3.7 and always do the try/except to also solves this. |
`_set_initial_conftests` could break on some systems if a very long option was passed, because the `Path.exists()` call raises an `OSError` instead of returning `False`. Fix pytest-dev#10169
`_set_initial_conftests` could break on some systems if a very long option was passed, because the `Path.exists()` call raises an `OSError` instead of returning `False`. Fix pytest-dev#10169
I have a custom flag defined in conftest.py, and when I try to assign it to a value that is too long pytest crashes before ever getting to my code. This reproduces even if the flag isn't defined, and even if the current working directory is
/
.Failing example:
If I reduce the length of the flag, I get the expected behavior for my project, and this different and expected error from my pytest MVP:
I did a little digging into my version of pytest (7.0.0) to make sure I wasn't doing something wrong, but it looks like there is a blind call to
pathlib.Path.exists()
with a path constructed from the argument in__init__.py
:It seems to me like there should be a try or something here, since in cases like mine the argument may not be a file at all, and that can cause OS level errors.
Operating System: Ubuntu 20.04 LTS
pip list
from the virtual environment you are usingThe text was updated successfully, but these errors were encountered: