config: expose Config for typing purposes
This type is used in hooks and fixtures. The constructor is publicly documented so is not marked private.
This commit is contained in:
parent
c198a7a67e
commit
88d84a5791
|
@ -2,6 +2,7 @@ The types of objects used in pytest's API are now exported so they may be used i
|
|||
|
||||
The newly-exported types are:
|
||||
|
||||
- ``pytest.Config`` for :class:`Config <pytest.Config>`.
|
||||
- ``pytest.Mark`` for :class:`marks <pytest.Mark>`.
|
||||
- ``pytest.MarkDecorator`` for :class:`mark decorators <pytest.MarkDecorator>`.
|
||||
- ``pytest.MarkGenerator`` for the :class:`pytest.mark <pytest.MarkGenerator>` singleton.
|
||||
|
|
|
@ -61,7 +61,7 @@ For information about fixtures, see :ref:`fixtures`. To see a complete list of a
|
|||
namespace of doctests.
|
||||
|
||||
pytestconfig [session scope]
|
||||
Session-scoped fixture that returns the :class:`_pytest.config.Config` object.
|
||||
Session-scoped fixture that returns the :class:`pytest.Config` object.
|
||||
|
||||
Example::
|
||||
|
||||
|
|
|
@ -179,12 +179,12 @@ Files will only be matched for configuration if:
|
|||
The files are considered in the order above. Options from multiple ``configfiles`` candidates
|
||||
are never merged - the first match wins.
|
||||
|
||||
The internal :class:`Config <_pytest.config.Config>` object (accessible via hooks or through the :fixture:`pytestconfig` fixture)
|
||||
The :class:`Config <pytest.Config>` object (accessible via hooks or through the :fixture:`pytestconfig` fixture)
|
||||
will subsequently carry these attributes:
|
||||
|
||||
- :attr:`config.rootpath <_pytest.config.Config.rootpath>`: the determined root directory, guaranteed to exist.
|
||||
- :attr:`config.rootpath <pytest.Config.rootpath>`: the determined root directory, guaranteed to exist.
|
||||
|
||||
- :attr:`config.inipath <_pytest.config.Config.inipath>`: the determined ``configfile``, may be ``None``
|
||||
- :attr:`config.inipath <pytest.Config.inipath>`: the determined ``configfile``, may be ``None``
|
||||
(it is named ``inipath`` for historical reasons).
|
||||
|
||||
.. versionadded:: 6.1
|
||||
|
|
|
@ -787,7 +787,7 @@ CollectReport
|
|||
Config
|
||||
~~~~~~
|
||||
|
||||
.. autoclass:: _pytest.config.Config()
|
||||
.. autoclass:: pytest.Config()
|
||||
:members:
|
||||
|
||||
ExceptionInfo
|
||||
|
|
|
@ -841,6 +841,7 @@ class Config:
|
|||
"""Access to configuration values, pluginmanager and plugin hooks.
|
||||
|
||||
:param PytestPluginManager pluginmanager:
|
||||
A pytest PluginManager.
|
||||
|
||||
:param InvocationParams invocation_params:
|
||||
Object containing parameters regarding the :func:`pytest.main`
|
||||
|
@ -1226,8 +1227,8 @@ class Config:
|
|||
|
||||
@hookimpl(hookwrapper=True)
|
||||
def pytest_collection(self) -> Generator[None, None, None]:
|
||||
"""Validate invalid ini keys after collection is done so we take in account
|
||||
options added by late-loading conftest files."""
|
||||
# Validate invalid ini keys after collection is done so we take in account
|
||||
# options added by late-loading conftest files.
|
||||
yield
|
||||
self._validate_config_options()
|
||||
|
||||
|
|
|
@ -189,7 +189,7 @@ class Parser:
|
|||
Default value if no ini-file option exists but is queried.
|
||||
|
||||
The value of ini-variables can be retrieved via a call to
|
||||
:py:func:`config.getini(name) <_pytest.config.Config.getini>`.
|
||||
:py:func:`config.getini(name) <pytest.Config.getini>`.
|
||||
"""
|
||||
assert type in (None, "string", "paths", "pathlist", "args", "linelist", "bool")
|
||||
self._inidict[name] = (help, type, default)
|
||||
|
|
|
@ -1379,7 +1379,8 @@ def yield_fixture(
|
|||
|
||||
@fixture(scope="session")
|
||||
def pytestconfig(request: FixtureRequest) -> Config:
|
||||
"""Session-scoped fixture that returns the :class:`_pytest.config.Config` object.
|
||||
"""Session-scoped fixture that returns the session's :class:`pytest.Config`
|
||||
object.
|
||||
|
||||
Example::
|
||||
|
||||
|
|
|
@ -100,12 +100,12 @@ def pytest_addoption(parser: "Parser", pluginmanager: "PytestPluginManager") ->
|
|||
to change how command line options are added.
|
||||
|
||||
Options can later be accessed through the
|
||||
:py:class:`config <_pytest.config.Config>` object, respectively:
|
||||
:py:class:`config <pytest.Config>` object, respectively:
|
||||
|
||||
- :py:func:`config.getoption(name) <_pytest.config.Config.getoption>` to
|
||||
- :py:func:`config.getoption(name) <pytest.Config.getoption>` to
|
||||
retrieve the value of a command line option.
|
||||
|
||||
- :py:func:`config.getini(name) <_pytest.config.Config.getini>` to retrieve
|
||||
- :py:func:`config.getini(name) <pytest.Config.getini>` to retrieve
|
||||
a value read from an ini-style file.
|
||||
|
||||
The config object is passed around on many internal objects via the ``.config``
|
||||
|
@ -129,7 +129,7 @@ def pytest_configure(config: "Config") -> None:
|
|||
.. note::
|
||||
This hook is incompatible with ``hookwrapper=True``.
|
||||
|
||||
:param _pytest.config.Config config: The pytest config object.
|
||||
:param pytest.Config config: The pytest config object.
|
||||
"""
|
||||
|
||||
|
||||
|
@ -166,7 +166,7 @@ def pytest_cmdline_preparse(config: "Config", args: List[str]) -> None:
|
|||
.. note::
|
||||
This hook will not be called for ``conftest.py`` files, only for setuptools plugins.
|
||||
|
||||
:param _pytest.config.Config config: The pytest config object.
|
||||
:param pytest.Config config: The pytest config object.
|
||||
:param List[str] args: Arguments passed on the command line.
|
||||
"""
|
||||
|
||||
|
@ -178,7 +178,7 @@ def pytest_cmdline_main(config: "Config") -> Optional[Union["ExitCode", int]]:
|
|||
|
||||
Stops at first non-None result, see :ref:`firstresult`.
|
||||
|
||||
:param _pytest.config.Config config: The pytest config object.
|
||||
:param pytest.Config config: The pytest config object.
|
||||
"""
|
||||
|
||||
|
||||
|
@ -191,7 +191,7 @@ def pytest_load_initial_conftests(
|
|||
.. note::
|
||||
This hook will not be called for ``conftest.py`` files, only for setuptools plugins.
|
||||
|
||||
:param _pytest.config.Config early_config: The pytest config object.
|
||||
:param pytest.Config early_config: The pytest config object.
|
||||
:param List[str] args: Arguments passed on the command line.
|
||||
:param _pytest.config.argparsing.Parser parser: To add command line options.
|
||||
"""
|
||||
|
@ -246,7 +246,7 @@ def pytest_collection_modifyitems(
|
|||
the items in-place.
|
||||
|
||||
:param pytest.Session session: The pytest session object.
|
||||
:param _pytest.config.Config config: The pytest config object.
|
||||
:param pytest.Config config: The pytest config object.
|
||||
:param List[pytest.Item] items: List of item objects.
|
||||
"""
|
||||
|
||||
|
@ -271,7 +271,7 @@ def pytest_ignore_collect(
|
|||
|
||||
:param pathlib.Path fspath: The path to analyze.
|
||||
:param LEGACY_PATH path: The path to analyze.
|
||||
:param _pytest.config.Config config: The pytest config object.
|
||||
:param pytest.Config config: The pytest config object.
|
||||
|
||||
.. versionchanged:: 6.3.0
|
||||
The ``fspath`` parameter was added as a :class:`pathlib.Path`
|
||||
|
@ -385,7 +385,7 @@ def pytest_make_parametrize_id(
|
|||
|
||||
Stops at first non-None result, see :ref:`firstresult`.
|
||||
|
||||
:param _pytest.config.Config config: The pytest config object.
|
||||
:param pytest.Config config: The pytest config object.
|
||||
:param val: The parametrized value.
|
||||
:param str argname: The automatic parameter name produced by pytest.
|
||||
"""
|
||||
|
@ -609,7 +609,7 @@ def pytest_sessionfinish(
|
|||
def pytest_unconfigure(config: "Config") -> None:
|
||||
"""Called before test process is exited.
|
||||
|
||||
:param _pytest.config.Config config: The pytest config object.
|
||||
:param pytest.Config config: The pytest config object.
|
||||
"""
|
||||
|
||||
|
||||
|
@ -628,7 +628,7 @@ def pytest_assertrepr_compare(
|
|||
*in* a string will be escaped. Note that all but the first line will
|
||||
be indented slightly, the intention is for the first line to be a summary.
|
||||
|
||||
:param _pytest.config.Config config: The pytest config object.
|
||||
:param pytest.Config config: The pytest config object.
|
||||
"""
|
||||
|
||||
|
||||
|
@ -677,7 +677,7 @@ def pytest_report_header(
|
|||
) -> Union[str, List[str]]:
|
||||
"""Return a string or list of strings to be displayed as header info for terminal reporting.
|
||||
|
||||
:param _pytest.config.Config config: The pytest config object.
|
||||
:param pytest.Config config: The pytest config object.
|
||||
:param Path startpath: The starting dir.
|
||||
:param LEGACY_PATH startdir: The starting dir.
|
||||
|
||||
|
@ -713,7 +713,7 @@ def pytest_report_collectionfinish(
|
|||
|
||||
.. versionadded:: 3.2
|
||||
|
||||
:param _pytest.config.Config config: The pytest config object.
|
||||
:param pytest.Config config: The pytest config object.
|
||||
:param Path startpath: The starting path.
|
||||
:param LEGACY_PATH startdir: The starting dir.
|
||||
: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(
|
|||
for example ``"rerun", "R", ("RERUN", {"yellow": True})``.
|
||||
|
||||
:param report: The report object whose status is to be returned.
|
||||
:param _pytest.config.Config config: The pytest config object.
|
||||
:param pytest.Config config: The pytest config object.
|
||||
|
||||
Stops at first non-None result, see :ref:`firstresult`.
|
||||
"""
|
||||
|
@ -767,7 +767,7 @@ def pytest_terminal_summary(
|
|||
|
||||
:param _pytest.terminal.TerminalReporter terminalreporter: The internal terminal reporter object.
|
||||
:param int exitstatus: The exit status that will be reported back to the OS.
|
||||
:param _pytest.config.Config config: The pytest config object.
|
||||
:param pytest.Config config: The pytest config object.
|
||||
|
||||
.. versionadded:: 4.2
|
||||
The ``config`` parameter.
|
||||
|
@ -857,7 +857,7 @@ def pytest_markeval_namespace(config: "Config") -> Dict[str, Any]:
|
|||
|
||||
.. versionadded:: 6.2
|
||||
|
||||
:param _pytest.config.Config config: The pytest config object.
|
||||
:param pytest.Config config: The pytest config object.
|
||||
:returns: A dictionary of additional globals to add.
|
||||
"""
|
||||
|
||||
|
@ -909,7 +909,7 @@ def pytest_enter_pdb(config: "Config", pdb: "pdb.Pdb") -> None:
|
|||
Can be used by plugins to take special action just before the python
|
||||
debugger enters interactive mode.
|
||||
|
||||
:param _pytest.config.Config config: The pytest config object.
|
||||
:param pytest.Config config: The pytest config object.
|
||||
:param pdb.Pdb pdb: The Pdb instance.
|
||||
"""
|
||||
|
||||
|
@ -920,6 +920,6 @@ def pytest_leave_pdb(config: "Config", pdb: "pdb.Pdb") -> None:
|
|||
Can be used by plugins to take special action just after the python
|
||||
debugger leaves interactive mode.
|
||||
|
||||
:param _pytest.config.Config config: The pytest config object.
|
||||
:param pytest.Config config: The pytest config object.
|
||||
:param pdb.Pdb pdb: The Pdb instance.
|
||||
"""
|
||||
|
|
|
@ -954,7 +954,7 @@ class Pytester:
|
|||
) -> Optional[Union[Collector, Item]]:
|
||||
"""Return the collection node of a file.
|
||||
|
||||
:param _pytest.config.Config config:
|
||||
:param pytest.Config config:
|
||||
A pytest config.
|
||||
See :py:meth:`parseconfig` and :py:meth:`parseconfigure` for creating it.
|
||||
:param os.PathLike[str] arg:
|
||||
|
@ -1186,7 +1186,7 @@ class Pytester:
|
|||
This invokes the pytest bootstrapping code in _pytest.config to create
|
||||
a new :py:class:`_pytest.core.PluginManager` and call the
|
||||
pytest_cmdline_parse hook to create a new
|
||||
:py:class:`_pytest.config.Config` instance.
|
||||
:py:class:`pytest.Config` instance.
|
||||
|
||||
If :py:attr:`plugins` has been populated they should be plugin modules
|
||||
to be registered with the PluginManager.
|
||||
|
@ -1206,7 +1206,7 @@ class Pytester:
|
|||
def parseconfigure(self, *args: Union[str, "os.PathLike[str]"]) -> Config:
|
||||
"""Return a new pytest configured Config instance.
|
||||
|
||||
Returns a new :py:class:`_pytest.config.Config` instance like
|
||||
Returns a new :py:class:`pytest.Config` instance like
|
||||
:py:meth:`parseconfig`, but also calls the pytest_configure hook.
|
||||
"""
|
||||
config = self.parseconfig(*args)
|
||||
|
|
|
@ -970,7 +970,7 @@ class Metafunc:
|
|||
#: Access to the underlying :class:`_pytest.python.FunctionDefinition`.
|
||||
self.definition = definition
|
||||
|
||||
#: Access to the :class:`_pytest.config.Config` object for the test session.
|
||||
#: Access to the :class:`pytest.Config` object for the test session.
|
||||
self.config = config
|
||||
|
||||
#: The module object where the test function is defined in.
|
||||
|
|
|
@ -7,6 +7,7 @@ from _pytest.assertion import register_assert_rewrite
|
|||
from _pytest.cacheprovider import Cache
|
||||
from _pytest.capture import CaptureFixture
|
||||
from _pytest.config import cmdline
|
||||
from _pytest.config import Config
|
||||
from _pytest.config import console_main
|
||||
from _pytest.config import ExitCode
|
||||
from _pytest.config import hookimpl
|
||||
|
@ -77,6 +78,7 @@ __all__ = [
|
|||
"cmdline",
|
||||
"collect",
|
||||
"Collector",
|
||||
"Config",
|
||||
"console_main",
|
||||
"deprecated_call",
|
||||
"exit",
|
||||
|
|
Loading…
Reference in New Issue