Skip to content

Commit 88d84a5

Browse files
committed
config: expose Config for typing purposes
This type is used in hooks and fixtures. The constructor is publicly documented so is not marked private.
1 parent c198a7a commit 88d84a5

File tree

11 files changed

+37
-32
lines changed

11 files changed

+37
-32
lines changed

changelog/7469.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ The types of objects used in pytest's API are now exported so they may be used i
22

33
The newly-exported types are:
44

5+
- ``pytest.Config`` for :class:`Config <pytest.Config>`.
56
- ``pytest.Mark`` for :class:`marks <pytest.Mark>`.
67
- ``pytest.MarkDecorator`` for :class:`mark decorators <pytest.MarkDecorator>`.
78
- ``pytest.MarkGenerator`` for the :class:`pytest.mark <pytest.MarkGenerator>` singleton.

doc/en/builtin.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ For information about fixtures, see :ref:`fixtures`. To see a complete list of a
6161
namespace of doctests.
6262
6363
pytestconfig [session scope]
64-
Session-scoped fixture that returns the :class:`_pytest.config.Config` object.
64+
Session-scoped fixture that returns the :class:`pytest.Config` object.
6565
6666
Example::
6767

doc/en/reference/customize.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,12 @@ Files will only be matched for configuration if:
179179
The files are considered in the order above. Options from multiple ``configfiles`` candidates
180180
are never merged - the first match wins.
181181

182-
The internal :class:`Config <_pytest.config.Config>` object (accessible via hooks or through the :fixture:`pytestconfig` fixture)
182+
The :class:`Config <pytest.Config>` object (accessible via hooks or through the :fixture:`pytestconfig` fixture)
183183
will subsequently carry these attributes:
184184

185-
- :attr:`config.rootpath <_pytest.config.Config.rootpath>`: the determined root directory, guaranteed to exist.
185+
- :attr:`config.rootpath <pytest.Config.rootpath>`: the determined root directory, guaranteed to exist.
186186

187-
- :attr:`config.inipath <_pytest.config.Config.inipath>`: the determined ``configfile``, may be ``None``
187+
- :attr:`config.inipath <pytest.Config.inipath>`: the determined ``configfile``, may be ``None``
188188
(it is named ``inipath`` for historical reasons).
189189

190190
.. versionadded:: 6.1

doc/en/reference/reference.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,7 @@ CollectReport
787787
Config
788788
~~~~~~
789789

790-
.. autoclass:: _pytest.config.Config()
790+
.. autoclass:: pytest.Config()
791791
:members:
792792

793793
ExceptionInfo

src/_pytest/config/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,7 @@ class Config:
841841
"""Access to configuration values, pluginmanager and plugin hooks.
842842
843843
:param PytestPluginManager pluginmanager:
844+
A pytest PluginManager.
844845
845846
:param InvocationParams invocation_params:
846847
Object containing parameters regarding the :func:`pytest.main`
@@ -1226,8 +1227,8 @@ def _preparse(self, args: List[str], addopts: bool = True) -> None:
12261227

12271228
@hookimpl(hookwrapper=True)
12281229
def pytest_collection(self) -> Generator[None, None, None]:
1229-
"""Validate invalid ini keys after collection is done so we take in account
1230-
options added by late-loading conftest files."""
1230+
# Validate invalid ini keys after collection is done so we take in account
1231+
# options added by late-loading conftest files.
12311232
yield
12321233
self._validate_config_options()
12331234

src/_pytest/config/argparsing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ def addini(
189189
Default value if no ini-file option exists but is queried.
190190
191191
The value of ini-variables can be retrieved via a call to
192-
:py:func:`config.getini(name) <_pytest.config.Config.getini>`.
192+
:py:func:`config.getini(name) <pytest.Config.getini>`.
193193
"""
194194
assert type in (None, "string", "paths", "pathlist", "args", "linelist", "bool")
195195
self._inidict[name] = (help, type, default)

src/_pytest/fixtures.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,8 @@ def yield_fixture(
13791379

13801380
@fixture(scope="session")
13811381
def pytestconfig(request: FixtureRequest) -> Config:
1382-
"""Session-scoped fixture that returns the :class:`_pytest.config.Config` object.
1382+
"""Session-scoped fixture that returns the session's :class:`pytest.Config`
1383+
object.
13831384
13841385
Example::
13851386

src/_pytest/hookspec.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ def pytest_addoption(parser: "Parser", pluginmanager: "PytestPluginManager") ->
100100
to change how command line options are added.
101101
102102
Options can later be accessed through the
103-
:py:class:`config <_pytest.config.Config>` object, respectively:
103+
:py:class:`config <pytest.Config>` object, respectively:
104104
105-
- :py:func:`config.getoption(name) <_pytest.config.Config.getoption>` to
105+
- :py:func:`config.getoption(name) <pytest.Config.getoption>` to
106106
retrieve the value of a command line option.
107107
108-
- :py:func:`config.getini(name) <_pytest.config.Config.getini>` to retrieve
108+
- :py:func:`config.getini(name) <pytest.Config.getini>` to retrieve
109109
a value read from an ini-style file.
110110
111111
The config object is passed around on many internal objects via the ``.config``
@@ -129,7 +129,7 @@ def pytest_configure(config: "Config") -> None:
129129
.. note::
130130
This hook is incompatible with ``hookwrapper=True``.
131131
132-
:param _pytest.config.Config config: The pytest config object.
132+
:param pytest.Config config: The pytest config object.
133133
"""
134134

135135

@@ -166,7 +166,7 @@ def pytest_cmdline_preparse(config: "Config", args: List[str]) -> None:
166166
.. note::
167167
This hook will not be called for ``conftest.py`` files, only for setuptools plugins.
168168
169-
:param _pytest.config.Config config: The pytest config object.
169+
:param pytest.Config config: The pytest config object.
170170
:param List[str] args: Arguments passed on the command line.
171171
"""
172172

@@ -178,7 +178,7 @@ def pytest_cmdline_main(config: "Config") -> Optional[Union["ExitCode", int]]:
178178
179179
Stops at first non-None result, see :ref:`firstresult`.
180180
181-
:param _pytest.config.Config config: The pytest config object.
181+
:param pytest.Config config: The pytest config object.
182182
"""
183183

184184

@@ -191,7 +191,7 @@ def pytest_load_initial_conftests(
191191
.. note::
192192
This hook will not be called for ``conftest.py`` files, only for setuptools plugins.
193193
194-
:param _pytest.config.Config early_config: The pytest config object.
194+
:param pytest.Config early_config: The pytest config object.
195195
:param List[str] args: Arguments passed on the command line.
196196
:param _pytest.config.argparsing.Parser parser: To add command line options.
197197
"""
@@ -246,7 +246,7 @@ def pytest_collection_modifyitems(
246246
the items in-place.
247247
248248
:param pytest.Session session: The pytest session object.
249-
:param _pytest.config.Config config: The pytest config object.
249+
:param pytest.Config config: The pytest config object.
250250
:param List[pytest.Item] items: List of item objects.
251251
"""
252252

@@ -271,7 +271,7 @@ def pytest_ignore_collect(
271271
272272
:param pathlib.Path fspath: The path to analyze.
273273
:param LEGACY_PATH path: The path to analyze.
274-
:param _pytest.config.Config config: The pytest config object.
274+
:param pytest.Config config: The pytest config object.
275275
276276
.. versionchanged:: 6.3.0
277277
The ``fspath`` parameter was added as a :class:`pathlib.Path`
@@ -385,7 +385,7 @@ def pytest_make_parametrize_id(
385385
386386
Stops at first non-None result, see :ref:`firstresult`.
387387
388-
:param _pytest.config.Config config: The pytest config object.
388+
:param pytest.Config config: The pytest config object.
389389
:param val: The parametrized value.
390390
:param str argname: The automatic parameter name produced by pytest.
391391
"""
@@ -609,7 +609,7 @@ def pytest_sessionfinish(
609609
def pytest_unconfigure(config: "Config") -> None:
610610
"""Called before test process is exited.
611611
612-
:param _pytest.config.Config config: The pytest config object.
612+
:param pytest.Config config: The pytest config object.
613613
"""
614614

615615

@@ -628,7 +628,7 @@ def pytest_assertrepr_compare(
628628
*in* a string will be escaped. Note that all but the first line will
629629
be indented slightly, the intention is for the first line to be a summary.
630630
631-
:param _pytest.config.Config config: The pytest config object.
631+
:param pytest.Config config: The pytest config object.
632632
"""
633633

634634

@@ -677,7 +677,7 @@ def pytest_report_header(
677677
) -> Union[str, List[str]]:
678678
"""Return a string or list of strings to be displayed as header info for terminal reporting.
679679
680-
:param _pytest.config.Config config: The pytest config object.
680+
:param pytest.Config config: The pytest config object.
681681
:param Path startpath: The starting dir.
682682
:param LEGACY_PATH startdir: The starting dir.
683683
@@ -713,7 +713,7 @@ def pytest_report_collectionfinish(
713713
714714
.. versionadded:: 3.2
715715
716-
:param _pytest.config.Config config: The pytest config object.
716+
:param pytest.Config config: The pytest config object.
717717
:param Path startpath: The starting path.
718718
:param LEGACY_PATH startdir: The starting dir.
719719
:param items: List of pytest items that are going to be executed; this list should not be modified.
@@ -752,7 +752,7 @@ def pytest_report_teststatus(
752752
for example ``"rerun", "R", ("RERUN", {"yellow": True})``.
753753
754754
:param report: The report object whose status is to be returned.
755-
:param _pytest.config.Config config: The pytest config object.
755+
:param pytest.Config config: The pytest config object.
756756
757757
Stops at first non-None result, see :ref:`firstresult`.
758758
"""
@@ -767,7 +767,7 @@ def pytest_terminal_summary(
767767
768768
:param _pytest.terminal.TerminalReporter terminalreporter: The internal terminal reporter object.
769769
:param int exitstatus: The exit status that will be reported back to the OS.
770-
:param _pytest.config.Config config: The pytest config object.
770+
:param pytest.Config config: The pytest config object.
771771
772772
.. versionadded:: 4.2
773773
The ``config`` parameter.
@@ -857,7 +857,7 @@ def pytest_markeval_namespace(config: "Config") -> Dict[str, Any]:
857857
858858
.. versionadded:: 6.2
859859
860-
:param _pytest.config.Config config: The pytest config object.
860+
:param pytest.Config config: The pytest config object.
861861
:returns: A dictionary of additional globals to add.
862862
"""
863863

@@ -909,7 +909,7 @@ def pytest_enter_pdb(config: "Config", pdb: "pdb.Pdb") -> None:
909909
Can be used by plugins to take special action just before the python
910910
debugger enters interactive mode.
911911
912-
:param _pytest.config.Config config: The pytest config object.
912+
:param pytest.Config config: The pytest config object.
913913
:param pdb.Pdb pdb: The Pdb instance.
914914
"""
915915

@@ -920,6 +920,6 @@ def pytest_leave_pdb(config: "Config", pdb: "pdb.Pdb") -> None:
920920
Can be used by plugins to take special action just after the python
921921
debugger leaves interactive mode.
922922
923-
:param _pytest.config.Config config: The pytest config object.
923+
:param pytest.Config config: The pytest config object.
924924
:param pdb.Pdb pdb: The Pdb instance.
925925
"""

src/_pytest/pytester.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ def getnode(
954954
) -> Optional[Union[Collector, Item]]:
955955
"""Return the collection node of a file.
956956
957-
:param _pytest.config.Config config:
957+
:param pytest.Config config:
958958
A pytest config.
959959
See :py:meth:`parseconfig` and :py:meth:`parseconfigure` for creating it.
960960
:param os.PathLike[str] arg:
@@ -1186,7 +1186,7 @@ def parseconfig(self, *args: Union[str, "os.PathLike[str]"]) -> Config:
11861186
This invokes the pytest bootstrapping code in _pytest.config to create
11871187
a new :py:class:`_pytest.core.PluginManager` and call the
11881188
pytest_cmdline_parse hook to create a new
1189-
:py:class:`_pytest.config.Config` instance.
1189+
:py:class:`pytest.Config` instance.
11901190
11911191
If :py:attr:`plugins` has been populated they should be plugin modules
11921192
to be registered with the PluginManager.
@@ -1206,7 +1206,7 @@ def parseconfig(self, *args: Union[str, "os.PathLike[str]"]) -> Config:
12061206
def parseconfigure(self, *args: Union[str, "os.PathLike[str]"]) -> Config:
12071207
"""Return a new pytest configured Config instance.
12081208
1209-
Returns a new :py:class:`_pytest.config.Config` instance like
1209+
Returns a new :py:class:`pytest.Config` instance like
12101210
:py:meth:`parseconfig`, but also calls the pytest_configure hook.
12111211
"""
12121212
config = self.parseconfig(*args)

src/_pytest/python.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ def __init__(
970970
#: Access to the underlying :class:`_pytest.python.FunctionDefinition`.
971971
self.definition = definition
972972

973-
#: Access to the :class:`_pytest.config.Config` object for the test session.
973+
#: Access to the :class:`pytest.Config` object for the test session.
974974
self.config = config
975975

976976
#: The module object where the test function is defined in.

0 commit comments

Comments
 (0)