Skip to content

Commit 5e73cb4

Browse files
committed
Always run playwright tests, more expensive but just makes sense to check all versions
1 parent 746a32e commit 5e73cb4

File tree

5 files changed

+62
-60
lines changed

5 files changed

+62
-60
lines changed

.github/workflows/playwright.yml

Lines changed: 0 additions & 31 deletions
This file was deleted.

.github/workflows/tests.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ jobs:
2727
python-version: ${{ matrix.python-version }}
2828
- name: Install dependencies
2929
run: |
30-
python -m pip install --upgrade pip tox
30+
python -m pip install --upgrade pip tox pytest-playwright
31+
32+
# Install playwright system dependencies
33+
- name: Install Playwright browsers
34+
run: |
35+
playwright install --with-deps chromium
36+
3137
- name: Run tox targets for ${{ matrix.python-version }}
3238
run: |
3339
ENV_PREFIX=$(tr -C -d "0-9" <<< "${{ matrix.python-version }}")

tests/conftest.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import os
2+
3+
import pytest
4+
5+
6+
@pytest.fixture(scope="function")
7+
def browser_context_args(browser_context_args):
8+
"""Modify browser context arguments for tracing."""
9+
return {
10+
**browser_context_args,
11+
"record_video_dir": os.path.join(os.getcwd(), "test-results/videos/"),
12+
"record_har_path": os.path.join(os.getcwd(), "test-results/har/", "test.har"),
13+
}
14+
15+
16+
@pytest.hookimpl(hookwrapper=True)
17+
def pytest_runtest_makereport(item, call):
18+
"""Handle reporting and artifact generation."""
19+
outcome = yield
20+
report = outcome.get_result()
21+
22+
# Take screenshot of failed tests
23+
if report.when == "call" and report.failed:
24+
try:
25+
page = item.funcargs["page"]
26+
# Take screenshot and save it with test name
27+
screenshot_dir = os.path.join(os.getcwd(), "screenshots")
28+
os.makedirs(screenshot_dir, exist_ok=True)
29+
screenshot_path = os.path.join(screenshot_dir, f"{item.name}_failed.png")
30+
page.screenshot(path=screenshot_path)
31+
# Save page HTML
32+
html_path = os.path.join(screenshot_dir, f"{item.name}_failed.html")
33+
with open(html_path, "w", encoding="utf-8") as f:
34+
f.write(page.content())
35+
36+
# Add to report
37+
report.extra = [
38+
{
39+
"name": "Screenshot",
40+
"content": screenshot_path,
41+
"mime_type": "image/png",
42+
},
43+
{"name": "HTML", "content": html_path, "mime_type": "text/html"},
44+
]
45+
except Exception as e:
46+
print(f"Failed to capture artifacts: {e}")

tests/testapp/test_prose_editor_e2e.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,17 @@
1-
import importlib.util
21
import os
32

43
import pytest
4+
from playwright.sync_api import expect
55

66
from testapp.models import ProseEditorModel
77

88

9-
# Check if playwright is installed
10-
playwright_available = importlib.util.find_spec("playwright") is not None
11-
12-
# Only import playwright modules if available
13-
if playwright_available:
14-
from playwright.sync_api import expect
15-
16-
179
# Set Django async unsafe to allow database operations in tests
1810
os.environ.setdefault("DJANGO_ALLOW_ASYNC_UNSAFE", "true")
1911

20-
# Skip reason for when playwright is not available
21-
requires_playwright = pytest.mark.skipif(
22-
not playwright_available, reason="Playwright not installed, skipping browser tests"
23-
)
24-
2512

2613
@pytest.mark.django_db
2714
@pytest.mark.e2e
28-
@requires_playwright
2915
def test_prose_editor_admin_form(page, live_server):
3016
"""Test that the prose editor loads and works in the admin."""
3117
# Login first
@@ -76,7 +62,6 @@ def test_prose_editor_admin_form(page, live_server):
7662

7763
@pytest.mark.django_db
7864
@pytest.mark.e2e
79-
@requires_playwright
8065
def test_prose_editor_formatting(page, live_server):
8166
"""Test formatting functionality in the prose editor."""
8267
# Login first

tox.ini

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ envlist =
66
[testenv]
77
usedevelop = true
88
extras = all,tests
9+
passenv =
10+
HOME
11+
PYTHONPATH
12+
DISPLAY
13+
XAUTHORITY
914
commands =
10-
pytest --cov=django_prose_editor --cov-report=term-missing tests/testapp {posargs}
15+
playwright install --with-deps chromium
16+
pytest --cov=django_prose_editor --cov-report=term-missing --browser chromium tests/testapp {posargs}
1117
coverage report -m
1218
deps =
1319
dj42: Django>=4.2,<5.0
@@ -16,17 +22,7 @@ deps =
1622
dj52: Django>=5.2a1,<6.0
1723
djmain: https://github.com/django/django/archive/main.tar.gz
1824

19-
[testenv:playwright]
20-
usedevelop = true
21-
extras = all,tests
22-
passenv =
23-
HOME
24-
PYTHONPATH
25-
DISPLAY
26-
XAUTHORITY
27-
commands =
28-
playwright install chromium
29-
pytest tests/testapp/test_prose_editor_e2e.py -v --browser chromium
25+
# The default testenv now includes Playwright
3026

3127
[testenv:docs]
3228
deps =

0 commit comments

Comments
 (0)