Skip to content

Commit 4f3f36c

Browse files
chrimahoChris Mahoney
and
Chris Mahoney
authored
Add alias --config-file to -c (#11036)
Fixes #11031 Signed-off-by: Chris Mahoney <[email protected]> Co-authored-by: Chris Mahoney <[email protected]>
1 parent af124c7 commit 4f3f36c

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ Charles Cloud
7272
Charles Machalow
7373
Charnjit SiNGH (CCSJ)
7474
Cheuk Ting Ho
75+
Chris Mahoney
7576
Chris Lamb
7677
Chris NeJame
7778
Chris Rose

changelog/11031.trivial.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.

doc/en/reference/reference.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1918,7 +1918,8 @@ All the command-line flags can be obtained by running ``pytest --help``::
19181918
--strict-markers Markers not registered in the `markers` section of
19191919
the configuration file raise errors
19201920
--strict (Deprecated) alias to --strict-markers
1921-
-c file Load configuration from `file` instead of trying to
1921+
-c, --config-file FILE
1922+
Load configuration from `FILE` instead of trying to
19221923
locate one of the implicit configuration files
19231924
--continue-on-collection-errors
19241925
Force test execution even if collection errors occur

src/_pytest/main.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,12 @@ def pytest_addoption(parser: Parser) -> None:
122122
)
123123
group._addoption(
124124
"-c",
125-
metavar="file",
125+
"--config-file",
126+
metavar="FILE",
126127
type=str,
127128
dest="inifilename",
128-
help="Load configuration from `file` instead of trying to locate one of the "
129-
"implicit configuration files",
129+
help="Load configuration from `FILE` instead of trying to locate one of the "
130+
"implicit configuration files.",
130131
)
131132
group._addoption(
132133
"--continue-on-collection-errors",

testing/test_config.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,8 @@ def pytest_addoption(parser):
514514
)
515515
config = pytester.parseconfig("-c", "custom.ini")
516516
assert config.getini("custom") == "1"
517+
config = pytester.parseconfig("--config-file", "custom.ini")
518+
assert config.getini("custom") == "1"
517519

518520
pytester.makefile(
519521
".cfg",
@@ -524,6 +526,8 @@ def pytest_addoption(parser):
524526
)
525527
config = pytester.parseconfig("-c", "custom_tool_pytest_section.cfg")
526528
assert config.getini("custom") == "1"
529+
config = pytester.parseconfig("--config-file", "custom_tool_pytest_section.cfg")
530+
assert config.getini("custom") == "1"
527531

528532
pytester.makefile(
529533
".toml",
@@ -536,6 +540,8 @@ def pytest_addoption(parser):
536540
)
537541
config = pytester.parseconfig("-c", "custom.toml")
538542
assert config.getini("custom") == "1"
543+
config = pytester.parseconfig("--config-file", "custom.toml")
544+
assert config.getini("custom") == "1"
539545

540546
def test_absolute_win32_path(self, pytester: Pytester) -> None:
541547
temp_ini_file = pytester.makefile(
@@ -550,6 +556,8 @@ def test_absolute_win32_path(self, pytester: Pytester) -> None:
550556
temp_ini_file_norm = normpath(str(temp_ini_file))
551557
ret = pytest.main(["-c", temp_ini_file_norm])
552558
assert ret == ExitCode.OK
559+
ret = pytest.main(["--config-file", temp_ini_file_norm])
560+
assert ret == ExitCode.OK
553561

554562

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

1918+
with pytest.raises(pytest.fail.Exception):
1919+
pytester.runpytest("--config-file", "custom.cfg")
1920+
19101921

19111922
class TestPytestPluginsVariable:
19121923
def test_pytest_plugins_in_non_top_level_conftest_unsupported(

0 commit comments

Comments
 (0)