Add support for .pytest.ini as an alternative to pytest.ini

Closes #9987
This commit is contained in:
Chris Wheeler 2022-06-14 07:24:35 -04:00 committed by GitHub
parent 2cd41651bb
commit fab696dcd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 18 additions and 7 deletions

View File

@ -67,6 +67,7 @@ Cheuk Ting Ho
Chris Lamb Chris Lamb
Chris NeJame Chris NeJame
Chris Rose Chris Rose
Chris Wheeler
Christian Boelsen Christian Boelsen
Christian Fetzer Christian Fetzer
Christian Neumüller Christian Neumüller

View File

@ -0,0 +1 @@
Added support for hidden configuration file by allowing ``.pytest.ini`` as an alternative to ``pytest.ini``.

View File

@ -29,9 +29,11 @@ pytest.ini
``pytest.ini`` files take precedence over other files, even when empty. ``pytest.ini`` files take precedence over other files, even when empty.
Alternatively, the hidden version ``.pytest.ini`` can be used.
.. code-block:: ini .. code-block:: ini
# pytest.ini # pytest.ini or .pytest.ini
[pytest] [pytest]
minversion = 6.0 minversion = 6.0
addopts = -ra -q addopts = -ra -q

View File

@ -1154,9 +1154,10 @@ Consult the :ref:`internal-warnings` section in the documentation for more infor
Configuration Options 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`` Here is a list of builtin configuration options that may be written in a ``pytest.ini`` (or ``.pytest.ini``),
file, usually located at the root of your repository. To see each file format in details, see ``pyproject.toml``, ``tox.ini``, or ``setup.cfg`` file, usually located at the root of your repository.
:ref:`config file formats`.
To see each file format in details, see :ref:`config file formats`.
.. warning:: .. warning::
Usage of ``setup.cfg`` is not recommended except for very simple use cases. ``.cfg`` Usage of ``setup.cfg`` is not recommended except for very simple use cases. ``.cfg``

View File

@ -96,6 +96,7 @@ def locate_config(
and return a tuple of (rootdir, inifile, cfg-dict).""" and return a tuple of (rootdir, inifile, cfg-dict)."""
config_names = [ config_names = [
"pytest.ini", "pytest.ini",
".pytest.ini",
"pyproject.toml", "pyproject.toml",
"tox.ini", "tox.ini",
"setup.cfg", "setup.cfg",

View File

@ -112,21 +112,26 @@ class TestParseIni:
@pytest.mark.parametrize( @pytest.mark.parametrize(
"section, name", "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: def test_ini_names(self, pytester: Pytester, name, section) -> None:
pytester.path.joinpath(name).write_text( pytester.path.joinpath(name).write_text(
textwrap.dedent( textwrap.dedent(
""" """
[{section}] [{section}]
minversion = 1.0 minversion = 3.36
""".format( """.format(
section=section section=section
) )
) )
) )
config = pytester.parseconfig() config = pytester.parseconfig()
assert config.getini("minversion") == "1.0" assert config.getini("minversion") == "3.36"
def test_pyproject_toml(self, pytester: Pytester) -> None: def test_pyproject_toml(self, pytester: Pytester) -> None:
pytester.makepyprojecttoml( pytester.makepyprojecttoml(