From 6389ab67ff9b5b46190e57027be665a8211fe598 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Tue, 16 Apr 2024 22:28:38 +0200 Subject: [PATCH] fix: clean up videos after each test --- pytest_playwright/pytest_playwright.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pytest_playwright/pytest_playwright.py b/pytest_playwright/pytest_playwright.py index db2cf0b..fd60bff 100644 --- a/pytest_playwright/pytest_playwright.py +++ b/pytest_playwright/pytest_playwright.py @@ -521,6 +521,14 @@ def did_finish_test(self, failed: bool) -> None: except Error: # Silent catch empty videos. pass + else: + for page in self._all_pages: + # Can be changed to "if page.video" without try/except once https://github.com/microsoft/playwright-python/pull/2410 is released and widely adopted. + if video_option in ["on", "retain-on-failure"]: + try: + page.video.delete() + except Error: + pass def on_did_create_browser_context(self, context: BrowserContext) -> None: context.on("page", lambda page: self._all_pages.append(page))