Skip to content
Merged
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
2 changes: 1 addition & 1 deletion py_pglite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
and Python test suites with support for SQLAlchemy, SQLModel, and Django.
"""

__version__ = "0.3.0"
__version__ = "0.3.1"

Check warning on line 7 in py_pglite/__init__.py

View check run for this annotation

Codecov / codecov/patch

py_pglite/__init__.py#L7

Added line #L7 was not covered by tests

# Core exports (always available)
# Database client exports (choose your preferred client)
Expand Down
78 changes: 61 additions & 17 deletions py_pglite/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,28 +119,73 @@

def pytest_runtest_setup(item: pytest.Item) -> None:
"""Setup each test with perfect framework isolation."""
# Check for missing dependencies with helpful messages
if item.get_closest_marker("pglite_sqlalchemy") and not HAS_SQLALCHEMY:
pytest.skip(
"🚫 SQLAlchemy not available.\n"
"Install with: pip install 'py-pglite[sqlalchemy]'"
)

if item.get_closest_marker("pglite_django") and not HAS_DJANGO:
pytest.skip(
"🚫 Django not available. Install with: pip install py-pglite[django]"
)

# Only check for pytest-django if the test is explicitly marked to use it
# Only skip if dependencies are missing AND test is explicitly marked
# (Don't skip auto-marked tests that might work with core fixtures)

# Check for explicit SQLAlchemy markers only
explicit_sqlalchemy_markers = {"sqlalchemy", "pglite_sqlalchemy"}
if any(item.get_closest_marker(marker) for marker in explicit_sqlalchemy_markers):
if not HAS_SQLALCHEMY and _is_explicitly_marked(
item, explicit_sqlalchemy_markers
):
print(f"Skipping test {item.name} because SQLAlchemy is not available")
pytest.skip(

Check warning on line 132 in py_pglite/pytest_plugin.py

View check run for this annotation

Codecov / codecov/patch

py_pglite/pytest_plugin.py#L131-L132

Added lines #L131 - L132 were not covered by tests
"🚫 SQLAlchemy not available.\n"
"Install with: pip install 'py-pglite[sqlalchemy]'"
)

# Check for explicit Django markers only
explicit_django_markers = {"django", "pglite_django"}
if any(item.get_closest_marker(marker) for marker in explicit_django_markers):
if not HAS_DJANGO and _is_explicitly_marked(item, explicit_django_markers):
print(f"Skipping test {item.name} because Django is not available")
pytest.skip(

Check warning on line 142 in py_pglite/pytest_plugin.py

View check run for this annotation

Codecov / codecov/patch

py_pglite/pytest_plugin.py#L141-L142

Added lines #L141 - L142 were not covered by tests
"🚫 Django not available. Install: pip install py-pglite[django]"
)

# Check for explicit pytest-django markers
if item.get_closest_marker("pytest_django") and not HAS_PYTEST_DJANGO:
pytest.skip(
"🚫 pytest-django not available. Install with: pip install pytest-django"
)
if _is_explicitly_marked(item, {"pytest_django"}):
pytest.skip(

Check warning on line 149 in py_pglite/pytest_plugin.py

View check run for this annotation

Codecov / codecov/patch

py_pglite/pytest_plugin.py#L148-L149

Added lines #L148 - L149 were not covered by tests
"🚫 pytest-django not available. Install: pip install pytest-django"
)

# Framework isolation warnings for better DX
_check_framework_isolation(item)


def _is_explicitly_marked(item: pytest.Item, marker_names: set[str]) -> bool:

Check warning on line 157 in py_pglite/pytest_plugin.py

View check run for this annotation

Codecov / codecov/patch

py_pglite/pytest_plugin.py#L157

Added line #L157 was not covered by tests
"""Check if test is explicitly marked (not auto-marked by plugin)."""
# Simple heuristic: if the test path contains framework names, likely explicit
test_path = str(item.fspath)

Check warning on line 160 in py_pglite/pytest_plugin.py

View check run for this annotation

Codecov / codecov/patch

py_pglite/pytest_plugin.py#L160

Added line #L160 was not covered by tests

# Framework-specific paths indicate explicit usage
if "sqlalchemy" in marker_names and "sqlalchemy" in test_path.lower():
return True
if "django" in marker_names and "django" in test_path.lower():
return True

Check warning on line 166 in py_pglite/pytest_plugin.py

View check run for this annotation

Codecov / codecov/patch

py_pglite/pytest_plugin.py#L163-L166

Added lines #L163 - L166 were not covered by tests

# Check if marker has arguments (explicit markers often have config)
for marker_name in marker_names:
marker = item.get_closest_marker(marker_name)
if marker and (marker.args or marker.kwargs):
return True

Check warning on line 172 in py_pglite/pytest_plugin.py

View check run for this annotation

Codecov / codecov/patch

py_pglite/pytest_plugin.py#L169-L172

Added lines #L169 - L172 were not covered by tests

# Check for module-level pytestmark (if accessible)
try:
module = getattr(item, "module", None)
if module and hasattr(module, "pytestmark"):
pytestmark = module.pytestmark
if isinstance(pytestmark, list):
return any(mark.name in marker_names for mark in pytestmark)

Check warning on line 180 in py_pglite/pytest_plugin.py

View check run for this annotation

Codecov / codecov/patch

py_pglite/pytest_plugin.py#L175-L180

Added lines #L175 - L180 were not covered by tests
else:
return pytestmark.name in marker_names
except AttributeError:
pass

Check warning on line 184 in py_pglite/pytest_plugin.py

View check run for this annotation

Codecov / codecov/patch

py_pglite/pytest_plugin.py#L182-L184

Added lines #L182 - L184 were not covered by tests

return False

Check warning on line 186 in py_pglite/pytest_plugin.py

View check run for this annotation

Codecov / codecov/patch

py_pglite/pytest_plugin.py#L186

Added line #L186 was not covered by tests


def _check_framework_isolation(item: pytest.Item) -> None:
"""Check and warn about potential framework isolation issues."""
fixture_names = getattr(item, "fixturenames", [])
Expand Down Expand Up @@ -192,7 +237,6 @@
"pglite_sqlalchemy_session",
"pglite_sqlalchemy_engine",
"pglite_config",
"pglite_manager",
}
if fixture_names & sqlalchemy_fixtures:
item.add_marker(pytest.mark.sqlalchemy)
Expand Down
Loading