Skip to content

Unable to pass a file through custom cli option #13368

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
MarcinKonowalczyk opened this issue Apr 10, 2025 · 0 comments
Closed

Unable to pass a file through custom cli option #13368

MarcinKonowalczyk opened this issue Apr 10, 2025 · 0 comments

Comments

@MarcinKonowalczyk
Copy link

to reproduce (with uv, but basically just from a fresh venv):

mkdir temp && cd temp
uv venv && .venv/bin/activate
pip install pytest
cat <<EOF > conftest.py
import pytest
def pytest_addoption(parser):
    parser.addoption(
        "--ruby",
        action="store",
        help="specify the ruby executable to use for tests",
    )
def pytest_configure(config):
    config.addinivalue_line("markers", "ruby: specify the ruby executable to use for tests")

@pytest.fixture(scope="session")
def ruby(request):
    return request.config.getoption("--ruby", None)
EOF
cat <<EOF | test_me.py
def test_me(ruby):
    print("Ruby: ", ruby)
EOF

and then

pytest --ruby '/usr/bin/not-ruby' # works ok and prints the path in test
pytest --ruby '/usr/bin/ruby' # fails

the error is:

ERROR: usage: pytest [options] [file_or_dir] [file_or_dir] [...]
pytest: error: unrecognized arguments: --ruby
  inifile: None
  rootdir: /usr/bin

looks like the parser is picking up the path as part of the root dir, but only if it exists...?

pip list output:

Package   Version
--------- -------
iniconfig 2.1.0
packaging 24.2
pluggy    1.5.0
pytest    8.3.5
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