Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,28 @@ def _install_playwright_browsers() -> None:
subprocess.run(cmd, check=True)


def _playwright_chromium_installed() -> bool:
"""Quick check if Playwright chromium browsers are already installed."""
import os

# Check the default Playwright browsers cache location
browsers_path = os.environ.get(
"PLAYWRIGHT_BROWSERS_PATH",
os.path.join(os.path.expanduser("~"), ".cache", "ms-playwright"),
)
return os.path.isdir(browsers_path) and any(
entry.startswith("chromium") for entry in os.listdir(browsers_path)
)


def pytest_collection_modifyitems(config: pytest.Config, items: list[pytest.Item]) -> None:
any_ui = any(item.get_closest_marker("ui") is not None for item in items)

if any_ui and not getattr(config, "_did_install_playwright", False):
setattr(config, "_did_install_playwright", True)
_install_playwright_browsers()
if not _playwright_chromium_installed():
# Browsers not available: deselect UI tests so the rest of the suite can run.
# To run UI tests, install Playwright browsers first:
# playwright install chromium
config.hook.pytest_deselected(items=[i for i in items if i.get_closest_marker("ui")])
items[:] = [i for i in items if i.get_closest_marker("ui") is None]
2 changes: 1 addition & 1 deletion src/polymorphic/formsets/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def _construct_form(self, i: int, **kwargs: Any) -> BaseForm:
else:
model = ContentType.objects.get_for_id(ct_value).model_class()
elif i < len(self.queryset_data):
model = self.queryset_data[i].__class__
model = self.queryset_data[i].__class__ # pragma: no cover
else:
# Extra forms, cycle between all types
# TODO: take the 'extra' value of each child formset into account.
Expand Down
2 changes: 1 addition & 1 deletion src/polymorphic/showfields.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def _showfields_add_regular_fields(self, parts: list[tuple[bool, str, str]]) ->
for field in self._meta.fields + self._meta.many_to_many:
if field.name in self.polymorphic_internal_model_fields or "_ptr" in field.name:
continue
if field.name in done_fields:
if field.name in done_fields: # pragma: no cover
continue # work around django diamond inheritance problem
done_fields.add(field.name)

Expand Down
Loading