Install the PEP 302 import hook if using assertion rewriting. Needs to parse the --assert=<mode> option from the commandline and find all the installed plugins to mark them for rewriting by the importhook.
(self)
| 1323 | ) |
| 1324 | |
| 1325 | def _consider_importhook(self) -> None: |
| 1326 | """Install the PEP 302 import hook if using assertion rewriting. |
| 1327 | |
| 1328 | Needs to parse the --assert=<mode> option from the commandline |
| 1329 | and find all the installed plugins to mark them for rewriting |
| 1330 | by the importhook. |
| 1331 | """ |
| 1332 | mode = getattr(self.known_args_namespace, "assertmode", "plain") |
| 1333 | |
| 1334 | disable_autoload = getattr( |
| 1335 | self.known_args_namespace, "disable_plugin_autoload", False |
| 1336 | ) or bool(os.environ.get("PYTEST_DISABLE_PLUGIN_AUTOLOAD")) |
| 1337 | if mode == "rewrite": |
| 1338 | import _pytest.assertion |
| 1339 | |
| 1340 | try: |
| 1341 | hook = _pytest.assertion.install_importhook(self) |
| 1342 | except SystemError: |
| 1343 | mode = "plain" |
| 1344 | else: |
| 1345 | self._mark_plugins_for_rewrite(hook, disable_autoload) |
| 1346 | self._warn_about_missing_assertion(mode) |
| 1347 | |
| 1348 | def _mark_plugins_for_rewrite( |
| 1349 | self, hook: AssertionRewritingHook, disable_autoload: bool |
no test coverage detected