From 768a645011f60d5fafa4f20a4542fecc3d63b508 Mon Sep 17 00:00:00 2001 From: Chris Wheeler Date: Mon, 23 May 2022 09:38:30 -0400 Subject: [PATCH 1/5] Allow config to exist in ".pytest.ini" Added config search option of ".pytest.ini" in addition to "pytest.ini" --- src/_pytest/config/findpaths.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/_pytest/config/findpaths.py b/src/_pytest/config/findpaths.py index ead344baac5..43c2367793e 100644 --- a/src/_pytest/config/findpaths.py +++ b/src/_pytest/config/findpaths.py @@ -96,6 +96,7 @@ def locate_config( and return a tuple of (rootdir, inifile, cfg-dict).""" config_names = [ "pytest.ini", + ".pytest.ini", "pyproject.toml", "tox.ini", "setup.cfg", From c8db42e394a473d7350fc70efc6163925a68c38e Mon Sep 17 00:00:00 2001 From: Chris Wheeler Date: Mon, 23 May 2022 09:46:34 -0400 Subject: [PATCH 2/5] Updated documentation to mention .pytest.ini Hidden version of pytest.ini documented. --- doc/en/reference/customize.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/en/reference/customize.rst b/doc/en/reference/customize.rst index fe10ca066b2..b6d21445a7e 100644 --- a/doc/en/reference/customize.rst +++ b/doc/en/reference/customize.rst @@ -29,9 +29,11 @@ pytest.ini ``pytest.ini`` files take precedence over other files, even when empty. +Alternatively, the hidden version ``.pytest.ini`` can be used. + .. code-block:: ini - # pytest.ini + # pytest.ini or .pytest.ini [pytest] minversion = 6.0 addopts = -ra -q From ef53f322931e1f96a78202519a8191cf4d6f2510 Mon Sep 17 00:00:00 2001 From: Chris Wheeler Date: Mon, 23 May 2022 09:58:40 -0400 Subject: [PATCH 3/5] Updated Changelog Added hidden configuration file info to changelog. --- changelog/9987.improvement.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/9987.improvement.rst diff --git a/changelog/9987.improvement.rst b/changelog/9987.improvement.rst new file mode 100644 index 00000000000..cb1ae17ad2c --- /dev/null +++ b/changelog/9987.improvement.rst @@ -0,0 +1 @@ +Added support for hidden configuration file by allowing ``.pytest.ini`` as an alternative to ``pytest.ini``. From b293e3b13f7faf48a0c9efd65cad547a27d94269 Mon Sep 17 00:00:00 2001 From: Chris Wheeler Date: Mon, 23 May 2022 09:59:56 -0400 Subject: [PATCH 4/5] Update AUTHORS Added myself to AUTHORS file. --- AUTHORS | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS b/AUTHORS index 86a814a137b..f0eead03ba5 100644 --- a/AUTHORS +++ b/AUTHORS @@ -66,6 +66,7 @@ Charnjit SiNGH (CCSJ) Chris Lamb Chris NeJame Chris Rose +Chris Wheeler Christian Boelsen Christian Fetzer Christian Neumüller From d940fc83836c33b585ba39bf4ef7fb8669baf240 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 14 Jun 2022 07:44:39 -0300 Subject: [PATCH 5/5] Add test and improve docs --- doc/en/reference/reference.rst | 7 ++++--- testing/test_config.py | 11 ++++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/doc/en/reference/reference.rst b/doc/en/reference/reference.rst index d082697258c..97fe20f5a60 100644 --- a/doc/en/reference/reference.rst +++ b/doc/en/reference/reference.rst @@ -1151,9 +1151,10 @@ Consult the :ref:`internal-warnings` section in the documentation for more infor Configuration Options --------------------- -Here is a list of builtin configuration options that may be written in a ``pytest.ini``, ``pyproject.toml``, ``tox.ini`` or ``setup.cfg`` -file, usually located at the root of your repository. To see each file format in details, see -:ref:`config file formats`. +Here is a list of builtin configuration options that may be written in a ``pytest.ini`` (or ``.pytest.ini``), +``pyproject.toml``, ``tox.ini``, or ``setup.cfg`` file, usually located at the root of your repository. + +To see each file format in details, see :ref:`config file formats`. .. warning:: Usage of ``setup.cfg`` is not recommended except for very simple use cases. ``.cfg`` diff --git a/testing/test_config.py b/testing/test_config.py index b2c74085eae..ca2ddd0af50 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -112,21 +112,26 @@ def test_tox_ini_wrong_version(self, pytester: Pytester) -> None: @pytest.mark.parametrize( "section, name", - [("tool:pytest", "setup.cfg"), ("pytest", "tox.ini"), ("pytest", "pytest.ini")], + [ + ("tool:pytest", "setup.cfg"), + ("pytest", "tox.ini"), + ("pytest", "pytest.ini"), + ("pytest", ".pytest.ini"), + ], ) def test_ini_names(self, pytester: Pytester, name, section) -> None: pytester.path.joinpath(name).write_text( textwrap.dedent( """ [{section}] - minversion = 1.0 + minversion = 3.36 """.format( section=section ) ) ) config = pytester.parseconfig() - assert config.getini("minversion") == "1.0" + assert config.getini("minversion") == "3.36" def test_pyproject_toml(self, pytester: Pytester) -> None: pytester.makepyprojecttoml(