MCPcopy Create free account
hub / github.com/seleniumbase/SeleniumBase / pytest_runtest_teardown

Function pytest_runtest_teardown

seleniumbase/plugins/pytest_plugin.py:2256–2324  ·  view source on GitHub ↗

This runs after every test with pytest.

(item)

Source from the content-addressed store, hash-verified

2254
2255
2256def pytest_runtest_teardown(item):
2257 """This runs after every test with pytest."""
2258 if "--co" in sys_argv or "--collect-only" in sys_argv:
2259 return
2260 with suppress(Exception):
2261 if hasattr(item, "_testcase") or hasattr(sb_config, "_sb_pdb_driver"):
2262 if hasattr(item, "_testcase"):
2263 self = item._testcase
2264 with suppress(Exception):
2265 if (
2266 getattr(self, "driver", None)
2267 and "--pdb" not in sys_argv
2268 ):
2269 if not (is_windows or self.driver.service.process):
2270 self.driver.quit()
2271 elif getattr(sb_config, "_sb_pdb_driver", None):
2272 with suppress(Exception):
2273 if (
2274 not is_windows
2275 or sb_config._sb_pdb_driver.service.process
2276 ):
2277 sb_config._sb_pdb_driver.quit()
2278 sb_config._sb_pdb_driver = None
2279 with suppress(Exception):
2280 if (
2281 getattr(self, "_xvfb_display", None)
2282 and hasattr(self._xvfb_display, "stop")
2283 and not getattr(sb_config, "reuse_session", None)
2284 ):
2285 self.headless_active = False
2286 sb_config.headless_active = False
2287 self._xvfb_display.stop()
2288 self._xvfb_display = None
2289 if (
2290 getattr(sb_config, "_virtual_display", None)
2291 and hasattr(sb_config._virtual_display, "stop")
2292 and not getattr(sb_config, "reuse_session", None)
2293 ):
2294 sb_config._virtual_display.stop()
2295 sb_config._virtual_display = None
2296 if (
2297 (
2298 sb_config._has_exception
2299 or (python3_11_or_newer and py311_patch2)
2300 or "--pdb" in sys_argv
2301 )
2302 and sb_config.list_fp
2303 and sb_config._fail_page
2304 ):
2305 if (
2306 "-s" in sys_argv
2307 or "--capture=no" in sys_argv
2308 or "--capture=tee-sys" in sys_argv
2309 or (
2310 hasattr(sb_config.pytest_config, "invocation_params")
2311 and (
2312 "-s" in sb_config.pytest_config.invocation_params.args
2313 or "--capture=no" in (

Callers

nothing calls this directly

Calls 3

writeMethod · 0.80
quitMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…