Skip to content

Instantly share code, notes, and snippets.

@klamann
Created May 20, 2025 08:40
Show Gist options
  • Save klamann/4ce4ba9380611966fe02be26167b9b8e to your computer and use it in GitHub Desktop.
Save klamann/4ce4ba9380611966fe02be26167b9b8e to your computer and use it in GitHub Desktop.
Skip a pytest integration tests when some resource is not available
from functools import cache
import pytest
@cache
def skip_if_no_database():
try:
MyDatabase().connect()
can_connect = True
except DatabaseError:
can_connect = False
return pytest.mark.skipif(not can_connect, reason="connection to database failed")
@skip_if_no_database()
def test_database():
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment