Skip to content

Commit

Permalink
Add alias --config-file to -c (#11036)
Browse files Browse the repository at this point in the history
Fixes #11031

Signed-off-by: Chris Mahoney <chrismahoey@hotmail.com>
Co-authored-by: Chris Mahoney <chrismahoey@hotmail.com>
  • Loading branch information
chrimaho and Chris Mahoney committed May 26, 2023
1 parent af124c7 commit 4f3f36c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Charles Cloud
Charles Machalow
Charnjit SiNGH (CCSJ)
Cheuk Ting Ho
Chris Mahoney
Chris Lamb
Chris NeJame
Chris Rose
Expand Down
1 change: 1 addition & 0 deletions changelog/11031.trivial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Enhanced the CLI flag for ``-c`` to now include ``--config-file`` to make it clear that this flag applies to the usage of a custom config file.
3 changes: 2 additions & 1 deletion doc/en/reference/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1918,7 +1918,8 @@ All the command-line flags can be obtained by running ``pytest --help``::
--strict-markers Markers not registered in the `markers` section of
the configuration file raise errors
--strict (Deprecated) alias to --strict-markers
-c file Load configuration from `file` instead of trying to
-c, --config-file FILE
Load configuration from `FILE` instead of trying to
locate one of the implicit configuration files
--continue-on-collection-errors
Force test execution even if collection errors occur
Expand Down
7 changes: 4 additions & 3 deletions src/_pytest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,12 @@ def pytest_addoption(parser: Parser) -> None:
)
group._addoption(
"-c",
metavar="file",
"--config-file",
metavar="FILE",
type=str,
dest="inifilename",
help="Load configuration from `file` instead of trying to locate one of the "
"implicit configuration files",
help="Load configuration from `FILE` instead of trying to locate one of the "
"implicit configuration files.",
)
group._addoption(
"--continue-on-collection-errors",
Expand Down
11 changes: 11 additions & 0 deletions testing/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,8 @@ def pytest_addoption(parser):
)
config = pytester.parseconfig("-c", "custom.ini")
assert config.getini("custom") == "1"
config = pytester.parseconfig("--config-file", "custom.ini")
assert config.getini("custom") == "1"

pytester.makefile(
".cfg",
Expand All @@ -524,6 +526,8 @@ def pytest_addoption(parser):
)
config = pytester.parseconfig("-c", "custom_tool_pytest_section.cfg")
assert config.getini("custom") == "1"
config = pytester.parseconfig("--config-file", "custom_tool_pytest_section.cfg")
assert config.getini("custom") == "1"

pytester.makefile(
".toml",
Expand All @@ -536,6 +540,8 @@ def pytest_addoption(parser):
)
config = pytester.parseconfig("-c", "custom.toml")
assert config.getini("custom") == "1"
config = pytester.parseconfig("--config-file", "custom.toml")
assert config.getini("custom") == "1"

def test_absolute_win32_path(self, pytester: Pytester) -> None:
temp_ini_file = pytester.makefile(
Expand All @@ -550,6 +556,8 @@ def test_absolute_win32_path(self, pytester: Pytester) -> None:
temp_ini_file_norm = normpath(str(temp_ini_file))
ret = pytest.main(["-c", temp_ini_file_norm])
assert ret == ExitCode.OK
ret = pytest.main(["--config-file", temp_ini_file_norm])
assert ret == ExitCode.OK


class TestConfigAPI:
Expand Down Expand Up @@ -1907,6 +1915,9 @@ def test_pytest_custom_cfg_unsupported(self, pytester: Pytester) -> None:
with pytest.raises(pytest.fail.Exception):
pytester.runpytest("-c", "custom.cfg")

with pytest.raises(pytest.fail.Exception):
pytester.runpytest("--config-file", "custom.cfg")


class TestPytestPluginsVariable:
def test_pytest_plugins_in_non_top_level_conftest_unsupported(
Expand Down

0 comments on commit 4f3f36c

Please sign in to comment.