Skip to content

Commit 8d762c5

Browse files
authored
Merge pull request #15 from wey-gu/fix_skip
fix skip issue
2 parents a1f00af + aa60bfa commit 8d762c5

File tree

2 files changed

+62
-18
lines changed

2 files changed

+62
-18
lines changed

py_pglite/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
and Python test suites with support for SQLAlchemy, SQLModel, and Django.
55
"""
66

7-
__version__ = "0.3.0"
7+
__version__ = "0.3.1"
88

99
# Core exports (always available)
1010
# Database client exports (choose your preferred client)

py_pglite/pytest_plugin.py

Lines changed: 61 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -119,28 +119,73 @@ def _should_disable_django_plugin(config: pytest.Config) -> bool:
119119

120120
def pytest_runtest_setup(item: pytest.Item) -> None:
121121
"""Setup each test with perfect framework isolation."""
122-
# Check for missing dependencies with helpful messages
123-
if item.get_closest_marker("pglite_sqlalchemy") and not HAS_SQLALCHEMY:
124-
pytest.skip(
125-
"🚫 SQLAlchemy not available.\n"
126-
"Install with: pip install 'py-pglite[sqlalchemy]'"
127-
)
128-
129-
if item.get_closest_marker("pglite_django") and not HAS_DJANGO:
130-
pytest.skip(
131-
"🚫 Django not available. Install with: pip install py-pglite[django]"
132-
)
133-
134-
# Only check for pytest-django if the test is explicitly marked to use it
122+
# Only skip if dependencies are missing AND test is explicitly marked
123+
# (Don't skip auto-marked tests that might work with core fixtures)
124+
125+
# Check for explicit SQLAlchemy markers only
126+
explicit_sqlalchemy_markers = {"sqlalchemy", "pglite_sqlalchemy"}
127+
if any(item.get_closest_marker(marker) for marker in explicit_sqlalchemy_markers):
128+
if not HAS_SQLALCHEMY and _is_explicitly_marked(
129+
item, explicit_sqlalchemy_markers
130+
):
131+
print(f"Skipping test {item.name} because SQLAlchemy is not available")
132+
pytest.skip(
133+
"🚫 SQLAlchemy not available.\n"
134+
"Install with: pip install 'py-pglite[sqlalchemy]'"
135+
)
136+
137+
# Check for explicit Django markers only
138+
explicit_django_markers = {"django", "pglite_django"}
139+
if any(item.get_closest_marker(marker) for marker in explicit_django_markers):
140+
if not HAS_DJANGO and _is_explicitly_marked(item, explicit_django_markers):
141+
print(f"Skipping test {item.name} because Django is not available")
142+
pytest.skip(
143+
"🚫 Django not available. Install: pip install py-pglite[django]"
144+
)
145+
146+
# Check for explicit pytest-django markers
135147
if item.get_closest_marker("pytest_django") and not HAS_PYTEST_DJANGO:
136-
pytest.skip(
137-
"🚫 pytest-django not available. Install with: pip install pytest-django"
138-
)
148+
if _is_explicitly_marked(item, {"pytest_django"}):
149+
pytest.skip(
150+
"🚫 pytest-django not available. Install: pip install pytest-django"
151+
)
139152

140153
# Framework isolation warnings for better DX
141154
_check_framework_isolation(item)
142155

143156

157+
def _is_explicitly_marked(item: pytest.Item, marker_names: set[str]) -> bool:
158+
"""Check if test is explicitly marked (not auto-marked by plugin)."""
159+
# Simple heuristic: if the test path contains framework names, likely explicit
160+
test_path = str(item.fspath)
161+
162+
# Framework-specific paths indicate explicit usage
163+
if "sqlalchemy" in marker_names and "sqlalchemy" in test_path.lower():
164+
return True
165+
if "django" in marker_names and "django" in test_path.lower():
166+
return True
167+
168+
# Check if marker has arguments (explicit markers often have config)
169+
for marker_name in marker_names:
170+
marker = item.get_closest_marker(marker_name)
171+
if marker and (marker.args or marker.kwargs):
172+
return True
173+
174+
# Check for module-level pytestmark (if accessible)
175+
try:
176+
module = getattr(item, "module", None)
177+
if module and hasattr(module, "pytestmark"):
178+
pytestmark = module.pytestmark
179+
if isinstance(pytestmark, list):
180+
return any(mark.name in marker_names for mark in pytestmark)
181+
else:
182+
return pytestmark.name in marker_names
183+
except AttributeError:
184+
pass
185+
186+
return False
187+
188+
144189
def _check_framework_isolation(item: pytest.Item) -> None:
145190
"""Check and warn about potential framework isolation issues."""
146191
fixture_names = getattr(item, "fixturenames", [])
@@ -192,7 +237,6 @@ def _auto_mark_test(item: pytest.Item) -> None:
192237
"pglite_sqlalchemy_session",
193238
"pglite_sqlalchemy_engine",
194239
"pglite_config",
195-
"pglite_manager",
196240
}
197241
if fixture_names & sqlalchemy_fixtures:
198242
item.add_marker(pytest.mark.sqlalchemy)

0 commit comments

Comments
 (0)