Skip to content

Addoption behaviour change with path as value #13351

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

Closed
4 tasks done
CreatingNull opened this issue Apr 4, 2025 · 0 comments
Closed
4 tasks done

Addoption behaviour change with path as value #13351

CreatingNull opened this issue Apr 4, 2025 · 0 comments

Comments

@CreatingNull
Copy link

CreatingNull commented Apr 4, 2025

Between 7.x -> 8.x there was a behavioral change with addoption (action=store) when values look like a directory paths. If such option-value pairs are provided as a list, pytest will add the value as a search-directory for tests (findpaths.get_dirs_from_args).

For example:

def pytest_addoption(parser):
    parser.addoption(
        "--random-path", action="store"
    )

pytest tests/ --random-path C:/Temp/

This causes weird behaviour, of note on Windows, if the adoption directory is say C:/Temp and you are running pytest from C:\Users\username\foo it can end up resolving a rootdir of C:/. This then triggers the searching permission bug raised in 11904, PermissionError: [WinError 5] Access is denied: 'C:\\Documents and Settings'.

The user-side fix is to pass optional arguments using option=value syntax instead of option value, but this may be an unintuitive fix based on how vague the error symptoms of this can be. As the path value will still eventually be added to the option config namespace, in many cases where intended tests are still discovered this doesn't cause a noticeable issue.

I'm not confident enough with the pytest source to submit a fix, but I'd assume you could consume your option's values before resolving search dirs? Otherwise a note in the docs on syntax requirements (key=val) for providing options with path's as values would probably also suffice?

Thanks for all your hard work, what an amazing tool and community you all have built!


Issue Checklist

  • a detailed description of the bug or problem you are having
  • output of pip list from the virtual environment you are using
Package   Version
--------- -------
colorama  0.4.6
iniconfig 2.1.0
packaging 24.2
pip       24.2
pluggy    1.5.0
pytest    8.3.5
  • pytest and operating system versions
    8.3.5 & Windows 11 Pro
  • minimal example if possible
    Somewhat difficult to provide an exact example
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants