Skip to content

Commit

Permalink
Move DEFAULT_VERSION to PgVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
bayandin committed Nov 10, 2024
1 parent cbbc725 commit 5f49295
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions test_runner/fixtures/pg_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,15 @@

# Inherit PgVersion from str rather than int to make it easier to pass as a command-line argument
# TODO: use enum.StrEnum for Python >= 3.11
@enum.unique
class PgVersion(str, enum.Enum):
V14 = "14"
V15 = "15"
V16 = "16"
V17 = "17"

# Default Postgres Version for tests that don't really depend on Postgres itself
DEFAULT = V16

# Instead of making version an optional parameter in methods, we can use this fake entry
# to explicitly rely on the default server version (could be different from pg_version fixture value)
NOT_SET = "<-POSTRGRES VERSION IS NOT SET->"
Expand Down Expand Up @@ -61,25 +64,22 @@ def _missing_(cls, value: object) -> Optional[PgVersion]:
return None


DEFAULT_VERSION: PgVersion = PgVersion.V16


def skip_on_postgres(version: PgVersion, reason: str):
return pytest.mark.skipif(
PgVersion(os.environ.get("DEFAULT_PG_VERSION", DEFAULT_VERSION)) is version,
PgVersion(os.environ.get("DEFAULT_PG_VERSION", PgVersion.DEFAULT)) is version,
reason=reason,
)


def xfail_on_postgres(version: PgVersion, reason: str):
return pytest.mark.xfail(
PgVersion(os.environ.get("DEFAULT_PG_VERSION", DEFAULT_VERSION)) is version,
PgVersion(os.environ.get("DEFAULT_PG_VERSION", PgVersion.DEFAULT)) is version,
reason=reason,
)


def run_only_on_default_postgres(reason: str):
return pytest.mark.skipif(
PgVersion(os.environ.get("DEFAULT_PG_VERSION", DEFAULT_VERSION)) is not DEFAULT_VERSION,
PgVersion(os.environ.get("DEFAULT_PG_VERSION", PgVersion.DEFAULT)) is not PgVersion.DEFAULT,
reason=reason,
)

0 comments on commit 5f49295

Please sign in to comment.