Run ``pytest.main()`` in-process, returning a HookRecorder. Runs the :py:func:`pytest.main` function to run all of pytest inside the test process itself. This means it can return a :py:class:`HookRecorder` instance which gives more detailed results from that run tha
(
self,
*args: str | os.PathLike[str],
plugins=(),
no_reraise_ctrlc: bool = False,
)
| 1087 | return items, rec |
| 1088 | |
| 1089 | def inline_run( |
| 1090 | self, |
| 1091 | *args: str | os.PathLike[str], |
| 1092 | plugins=(), |
| 1093 | no_reraise_ctrlc: bool = False, |
| 1094 | ) -> HookRecorder: |
| 1095 | """Run ``pytest.main()`` in-process, returning a HookRecorder. |
| 1096 | |
| 1097 | Runs the :py:func:`pytest.main` function to run all of pytest inside |
| 1098 | the test process itself. This means it can return a |
| 1099 | :py:class:`HookRecorder` instance which gives more detailed results |
| 1100 | from that run than can be done by matching stdout/stderr from |
| 1101 | :py:meth:`runpytest`. |
| 1102 | |
| 1103 | :param args: |
| 1104 | Command line arguments to pass to :py:func:`pytest.main`. |
| 1105 | :param plugins: |
| 1106 | Extra plugin instances the ``pytest.main()`` instance should use. |
| 1107 | :param no_reraise_ctrlc: |
| 1108 | Typically we reraise keyboard interrupts from the child run. If |
| 1109 | True, the KeyboardInterrupt exception is captured. |
| 1110 | """ |
| 1111 | from _pytest.unraisableexception import gc_collect_iterations_key |
| 1112 | |
| 1113 | # (maybe a cpython bug?) the importlib cache sometimes isn't updated |
| 1114 | # properly between file creation and inline_run (especially if imports |
| 1115 | # are interspersed with file creation) |
| 1116 | importlib.invalidate_caches() |
| 1117 | |
| 1118 | plugins = list(plugins) |
| 1119 | finalizers = [] |
| 1120 | try: |
| 1121 | # Any sys.module or sys.path changes done while running pytest |
| 1122 | # inline should be reverted after the test run completes to avoid |
| 1123 | # clashing with later inline tests run within the same pytest test, |
| 1124 | # e.g. just because they use matching test module names. |
| 1125 | finalizers.append(self.__take_sys_modules_snapshot().restore) |
| 1126 | finalizers.append(SysPathsSnapshot().restore) |
| 1127 | |
| 1128 | # Important note: |
| 1129 | # - our tests should not leave any other references/registrations |
| 1130 | # laying around other than possibly loaded test modules |
| 1131 | # referenced from sys.modules, as nothing will clean those up |
| 1132 | # automatically |
| 1133 | |
| 1134 | rec = [] |
| 1135 | |
| 1136 | class PytesterHelperPlugin: |
| 1137 | @staticmethod |
| 1138 | def pytest_configure(config: Config) -> None: |
| 1139 | rec.append(self.make_hook_recorder(config.pluginmanager)) |
| 1140 | |
| 1141 | # The unraisable plugin GC collect slows down inline |
| 1142 | # pytester runs too much. |
| 1143 | config.stash[gc_collect_iterations_key] = 0 |
| 1144 | |
| 1145 | plugins.append(PytesterHelperPlugin()) |
| 1146 | ret = main([str(x) for x in args], plugins=plugins) |
no test coverage detected