Created
May 20, 2025 08:40
-
-
Save klamann/4ce4ba9380611966fe02be26167b9b8e to your computer and use it in GitHub Desktop.
Skip a pytest integration tests when some resource is not available
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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