Skip to content

Commit 1ba5b48

Browse files
authored
Merge pull request #8697 from bluetech/expose-config
config: expose Config and PytestPluginManager for typing purposes
2 parents 1b5f532 + 9719237 commit 1ba5b48

File tree

12 files changed

+53
-40
lines changed

12 files changed

+53
-40
lines changed

changelog/7469.feature.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ 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.
89
- ``pytest.Metafunc`` for the :class:`metafunc <pytest.MarkGenerator>` argument to the :func:`pytest_generate_tests <pytest.hookspec.pytest_generate_tests>` hook.
910
- ``pytest.CallInfo`` for the :class:`CallInfo <pytest.CallInfo>` type passed to various hooks.
11+
- ``pytest.PytestPluginManager`` for :class:`PytestPluginManager <pytest.PytestPluginManager>`.
1012
- ``pytest.ExceptionInfo`` for the :class:`ExceptionInfo <pytest.ExceptionInfo>` type returned from :func:`pytest.raises` and passed to various hooks.
1113
- ``pytest.Parser`` for the :class:`Parser <pytest.Parser>` type passed to the :func:`pytest_addoption <pytest.hookspec.pytest_addoption>` hook.
1214
- ``pytest.OptionGroup`` for the :class:`OptionGroup <pytest.OptionGroup>` type returned from the :func:`parser.addgroup <pytest.Parser.getgroup>` method.

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/how-to/writing_plugins.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ testing directory:
337337
Alternatively you can invoke pytest with the ``-p pytester`` command line
338338
option.
339339

340-
This will allow you to use the :py:class:`pytester <_pytest.pytester.Pytester>`
340+
This will allow you to use the :py:class:`pytester <pytest.Pytester>`
341341
fixture for testing your plugin code.
342342

343343
Let's demonstrate what you can do with the plugin with an example. Imagine we

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: 2 additions & 2 deletions
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
@@ -901,7 +901,7 @@ OptionGroup
901901
PytestPluginManager
902902
~~~~~~~~~~~~~~~~~~~
903903

904-
.. autoclass:: _pytest.config.PytestPluginManager()
904+
.. autoclass:: pytest.PytestPluginManager()
905905
:members:
906906
:undoc-members:
907907
:inherited-members:

src/_pytest/config/__init__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ def get_config(
290290

291291
def get_plugin_manager() -> "PytestPluginManager":
292292
"""Obtain a new instance of the
293-
:py:class:`_pytest.config.PytestPluginManager`, with default plugins
293+
:py:class:`pytest.PytestPluginManager`, with default plugins
294294
already loaded.
295295
296296
This function can be used by integration with other tools, like hooking
@@ -632,6 +632,7 @@ def _check_non_top_pytest_plugins(
632632
def consider_preparse(
633633
self, args: Sequence[str], *, exclude_only: bool = False
634634
) -> None:
635+
""":meta private:"""
635636
i = 0
636637
n = len(args)
637638
while i < n:
@@ -653,6 +654,7 @@ def consider_preparse(
653654
self.consider_pluginarg(parg)
654655

655656
def consider_pluginarg(self, arg: str) -> None:
657+
""":meta private:"""
656658
if arg.startswith("no:"):
657659
name = arg[3:]
658660
if name in essential_plugins:
@@ -678,12 +680,15 @@ def consider_pluginarg(self, arg: str) -> None:
678680
self.import_plugin(arg, consider_entry_points=True)
679681

680682
def consider_conftest(self, conftestmodule: types.ModuleType) -> None:
683+
""":meta private:"""
681684
self.register(conftestmodule, name=conftestmodule.__file__)
682685

683686
def consider_env(self) -> None:
687+
""":meta private:"""
684688
self._import_plugin_specs(os.environ.get("PYTEST_PLUGINS"))
685689

686690
def consider_module(self, mod: types.ModuleType) -> None:
691+
""":meta private:"""
687692
self._import_plugin_specs(getattr(mod, "pytest_plugins", []))
688693

689694
def _import_plugin_specs(
@@ -841,6 +846,7 @@ class Config:
841846
"""Access to configuration values, pluginmanager and plugin hooks.
842847
843848
:param PytestPluginManager pluginmanager:
849+
A pytest PluginManager.
844850
845851
:param InvocationParams invocation_params:
846852
Object containing parameters regarding the :func:`pytest.main`
@@ -1227,8 +1233,8 @@ def _preparse(self, args: List[str], addopts: bool = True) -> None:
12271233

12281234
@hookimpl(hookwrapper=True)
12291235
def pytest_collection(self) -> Generator[None, None, None]:
1230-
"""Validate invalid ini keys after collection is done so we take in account
1231-
options added by late-loading conftest files."""
1236+
# Validate invalid ini keys after collection is done so we take in account
1237+
# options added by late-loading conftest files.
12321238
yield
12331239
self._validate_config_options()
12341240

src/_pytest/config/argparsing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def addini(
193193
Default value if no ini-file option exists but is queried.
194194
195195
The value of ini-variables can be retrieved via a call to
196-
:py:func:`config.getini(name) <_pytest.config.Config.getini>`.
196+
:py:func:`config.getini(name) <pytest.Config.getini>`.
197197
"""
198198
assert type in (None, "string", "paths", "pathlist", "args", "linelist", "bool")
199199
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: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def pytest_addhooks(pluginmanager: "PytestPluginManager") -> None:
5656
"""Called at plugin registration time to allow adding new hooks via a call to
5757
``pluginmanager.add_hookspecs(module_or_class, prefix)``.
5858
59-
:param _pytest.config.PytestPluginManager pluginmanager: pytest plugin manager.
59+
:param pytest.PytestPluginManager pluginmanager: The pytest plugin manager.
6060
6161
.. note::
6262
This hook is incompatible with ``hookwrapper=True``.
@@ -70,7 +70,7 @@ def pytest_plugin_registered(
7070
"""A new pytest plugin got registered.
7171
7272
:param plugin: The plugin module or instance.
73-
:param _pytest.config.PytestPluginManager manager: pytest plugin manager.
73+
:param pytest.PytestPluginManager manager: pytest plugin manager.
7474
7575
.. note::
7676
This hook is incompatible with ``hookwrapper=True``.
@@ -94,18 +94,18 @@ def pytest_addoption(parser: "Parser", pluginmanager: "PytestPluginManager") ->
9494
To add ini-file values call :py:func:`parser.addini(...)
9595
<pytest.Parser.addini>`.
9696
97-
:param _pytest.config.PytestPluginManager pluginmanager:
98-
pytest plugin manager, which can be used to install :py:func:`hookspec`'s
97+
:param pytest.PytestPluginManager pluginmanager:
98+
The pytest plugin manager, which can be used to install :py:func:`hookspec`'s
9999
or :py:func:`hookimpl`'s and allow one plugin to call another plugin's hooks
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

@@ -152,7 +152,7 @@ def pytest_cmdline_parse(
152152
``plugins`` arg when using `pytest.main`_ to perform an in-process
153153
test run.
154154
155-
:param _pytest.config.PytestPluginManager pluginmanager: Pytest plugin manager.
155+
:param pytest.PytestPluginManager pluginmanager: The pytest plugin manager.
156156
:param List[str] args: List of arguments passed on the command line.
157157
"""
158158

@@ -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.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)