You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
deftest_root_dir(pytester, pytestconfig) ->None:
pytester.makeconftest(
""" def pytest_addoption(parser): # assuming a user defined plugin that requires output directory parser.addoption("--some-dir")"""
)
pytester.makepyfile(
f""" def test_pass(pytestconfig): assert str(pytestconfig.rootpath) == r"{pytester.path}" """
)
# not passing this value or specifying it in ini addopts wont affect root dirresult=pytester.runpytest()
assertresult.ret==0# passing CLI as --<arg>=<val> wont affect root dir as wellresult=pytester.runpytest(f"--some-dir={pytester.path.parent}")
assertresult.ret==0# passing CLI as --<arg> <val> affects root dir result=pytester.runpytest("--some-dir", str(pytester.path.parent))
assertresult.ret==0# <-- test will fail here
It is really strange why supplying both --arg=val and --arg val is parsed correctly but the last one affects the root dir
The text was updated successfully, but these errors were encountered:
Unfortunately this is a known issue: because plugins can add their own command-line options, pytest uses a feature to parse its options that sets aside "unknown options" to be processed later, and processes the known options at startup.
The problem here is that when first looking at --some-dir somepath, the command-line parser can't know beforehand if --some-dir takes a parameter or is a flag (for example, like --verbose is a flag), so the parser doesn't associate the two arguments, and pytest ends up interpreting somepath as an extra argument passed to it. When using --some-dir=somepath, there's no ambiguity because it is clear to the parser that --some-dir is taking the somepath argument.
Unfortunately we don't have a solution to this atm.
The following test exposes the issue
It is really strange why supplying both
--arg=val
and--arg val
is parsed correctly but the last one affects the root dirThe text was updated successfully, but these errors were encountered: