Skip to content

Commit 5b16d49

Browse files
committed
revert playwright browser install change, address review findings
1 parent 47ebd5b commit 5b16d49

2 files changed

Lines changed: 15 additions & 51 deletions

File tree

conftest.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -66,28 +66,9 @@ def _install_playwright_browsers() -> None:
6666
subprocess.run(cmd, check=True)
6767

6868

69-
def _playwright_chromium_installed() -> bool:
70-
"""Quick check if Playwright chromium browsers are already installed."""
71-
import os
72-
73-
# Check the default Playwright browsers cache location
74-
browsers_path = os.environ.get(
75-
"PLAYWRIGHT_BROWSERS_PATH",
76-
os.path.join(os.path.expanduser("~"), ".cache", "ms-playwright"),
77-
)
78-
return os.path.isdir(browsers_path) and any(
79-
entry.startswith("chromium") for entry in os.listdir(browsers_path)
80-
)
81-
82-
8369
def pytest_collection_modifyitems(config: pytest.Config, items: list[pytest.Item]) -> None:
8470
any_ui = any(item.get_closest_marker("ui") is not None for item in items)
8571

8672
if any_ui and not getattr(config, "_did_install_playwright", False):
8773
setattr(config, "_did_install_playwright", True)
88-
if not _playwright_chromium_installed():
89-
# Browsers not available: deselect UI tests so the rest of the suite can run.
90-
# To run UI tests, install Playwright browsers first:
91-
# playwright install chromium
92-
config.hook.pytest_deselected(items=[i for i in items if i.get_closest_marker("ui")])
93-
items[:] = [i for i in items if i.get_closest_marker("ui") is None]
74+
_install_playwright_browsers()

src/polymorphic/tests/test_missing_coverage.py

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -321,28 +321,6 @@ class FakeConnection:
321321
results = list(qs)
322322
assert len(results) >= 2
323323

324-
def test_max_chunk_zero_uses_default(self):
325-
"""Test the code path where max_query_params=0 → use Polymorphic_QuerySet_objects_per_request."""
326-
from unittest.mock import patch, PropertyMock
327-
328-
import django.db.backends.base.features as features_module
329-
330-
Model2A.objects.create(field1="mq_zero_a")
331-
Model2B.objects.create(field1="mq_zero_b", field2="B2")
332-
333-
qs = Model2A.objects.all()
334-
335-
# Patch the connection features to return 0 for max_query_params
336-
with patch("django.db.connections") as mock_connections:
337-
mock_features = type("MockFeatures", (), {"max_query_params": 0})()
338-
mock_connection = type("MockConn", (), {"features": mock_features})()
339-
mock_connections.__getitem__ = lambda self, key: mock_connection
340-
341-
# Can't easily use this - instead verify the existing behavior
342-
# The default is 2000 - just verify it works
343-
results = list(qs)
344-
assert len(results) >= 2
345-
346324

347325
# ===========================================================================
348326
# query.py - non_polymorphic() False branch of issubclass check (lines 216->218)
@@ -1203,16 +1181,20 @@ def test_unbound_formset_ct_as_int(self):
12031181

12041182

12051183
# ===========================================================================
1206-
# formsets/models.py - model from queryset_data (line 255)
1184+
# formsets/models.py - per-row model selection for an unbound formset
12071185
# ===========================================================================
12081186

12091187

12101188
class TestFormsetModelFromQuerysetData(TestCase):
1211-
"""Test unbound formset where model comes from queryset_data."""
1189+
"""Test that an unbound formset built from a mixed-type queryset selects the
1190+
correct child model for each row."""
12121191

12131192
def test_model_from_queryset_data(self):
12141193
"""
1215-
Line 255: When no instance or initial, model comes from queryset_data[i].__class__.
1194+
Each initial form is bound to its queryset object's real concrete class
1195+
(the ``defaults["instance"]`` branch in ``_construct_form``), so a formset
1196+
over a mixed Model2A/Model2B queryset produces one correctly-typed form
1197+
per row.
12161198
"""
12171199
obj_a = Model2A.objects.create(field1="qs_data_a")
12181200
obj_b = Model2B.objects.create(field1="qs_data_b", field2="B2")
@@ -1234,10 +1216,9 @@ def test_model_from_queryset_data(self):
12341216
forms = formset.forms
12351217
# The form types come from the queryset_data items
12361218
assert len(forms) == 2
1237-
# At least one form for each type
1238-
field1s = {form.instance.__class__.__name__ for form in forms if form.instance.pk}
1239-
# queryset_data drives the model for each form
1240-
assert len(forms) == 2
1219+
# queryset_data drives the model for each form: one Model2A and one Model2B
1220+
form_models = {form.instance.__class__ for form in forms if form.instance.pk}
1221+
assert form_models == {Model2A, Model2B}
12411222

12421223

12431224
# ===========================================================================
@@ -1896,5 +1877,7 @@ def patched_is_valid(self_inner, *args, **kwargs):
18961877

18971878
with mock.patch.object(drf_serializers.Serializer, "is_valid", patched_is_valid):
18981879
result = s.is_valid()
1899-
# Result depends on child validation (child is valid, so True)
1900-
# But _validated_data was deleted before the check, so branch 98->101 executes
1880+
# _validated_data was deleted before the check, so branch 98->101 executes:
1881+
# the child's _validated_data is NOT merged into the parent, but no
1882+
# AttributeError is raised and is_valid still returns True (parent + child valid).
1883+
assert result is True

0 commit comments

Comments
 (0)