Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
Jun 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Charnjit SiNGH (CCSJ)
Chris Lamb
Chris NeJame
Chris Rose
Chris Wheeler
Christian Boelsen
Christian Fetzer
Christian Neumüller
Expand Down
1 change: 1 addition & 0 deletions changelog/9987.improvement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added support for hidden configuration file by allowing ``.pytest.ini`` as an alternative to ``pytest.ini``.
4 changes: 3 additions & 1 deletion doc/en/reference/customize.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions doc/en/reference/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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``
Expand Down
1 change: 1 addition & 0 deletions src/_pytest/config/findpaths.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 8 additions & 3 deletions testing/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used a more unusual version number than 1.0 just to be more clear that we are getting the actual value (1.0 seems a bit like it could be a default value).

""".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(
Expand Down