mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-04 20:12:54 +00:00
## Problem All tests have already been parametrised by Postgres version and build type (to have them distinguishable in the Allure report), but despite it, it's anyway required to have DEFAULT_PG_VERSION and BUILD_TYPE env vars set to corresponding values, for example to run`test_timeline_deletion_with_files_stuck_in_upload_queue[release-pg14-local_fs]` test it's required to set `DEFAULT_PG_VERSION=14` and `BUILD_TYPE=release`. This PR makes the test framework pick up parameters from the test name itself. ## Summary of changes - Postgres version and build type related fixtures now are function-scoped (instead of being sessions scoped before) - Deprecate `--pg-version` argument in favour of DEFAULT_PG_VERSION env variable (it's easier to parse) - GitHub autocomment now includes only one command with all the failed tests + runs them in parallel
83 lines
2.6 KiB
Python
83 lines
2.6 KiB
Python
import enum
|
|
import os
|
|
from typing import Optional
|
|
|
|
import pytest
|
|
from _pytest.config import Config
|
|
from _pytest.config.argparsing import Parser
|
|
|
|
"""
|
|
This fixture is used to determine which version of Postgres to use for tests.
|
|
"""
|
|
|
|
|
|
# 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"
|
|
# 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->"
|
|
|
|
# Make it less confusing in logs
|
|
def __repr__(self) -> str:
|
|
return f"'{self.value}'"
|
|
|
|
# Make this explicit for Python 3.11 compatibility, which changes the behavior of enums
|
|
def __str__(self) -> str:
|
|
return self.value
|
|
|
|
# In GitHub workflows we use Postgres version with v-prefix (e.g. v14 instead of just 14),
|
|
# sometime we need to do so in tests.
|
|
@property
|
|
def v_prefixed(self) -> str:
|
|
return f"v{self.value}"
|
|
|
|
@classmethod
|
|
def _missing_(cls, value) -> Optional["PgVersion"]:
|
|
known_values = {v.value for _, v in cls.__members__.items()}
|
|
|
|
# Allow passing version as a string with "v" prefix (e.g. "v14")
|
|
if isinstance(value, str) and value.lower().startswith("v") and value[1:] in known_values:
|
|
return cls(value[1:])
|
|
# Allow passing version as an int (e.g. 15 or 150002, both will be converted to PgVersion.V15)
|
|
elif isinstance(value, int) and str(value)[:2] in known_values:
|
|
return cls(str(value)[:2])
|
|
|
|
# Make mypy happy
|
|
# See https://github.com/python/mypy/issues/3974
|
|
return None
|
|
|
|
|
|
DEFAULT_VERSION: PgVersion = PgVersion.V14
|
|
|
|
|
|
def skip_on_postgres(version: PgVersion, reason: str):
|
|
return pytest.mark.skipif(
|
|
PgVersion(os.environ.get("DEFAULT_PG_VERSION", DEFAULT_VERSION)) 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,
|
|
reason=reason,
|
|
)
|
|
|
|
|
|
def pytest_addoption(parser: Parser):
|
|
parser.addoption(
|
|
"--pg-version",
|
|
action="store",
|
|
type=PgVersion,
|
|
help="DEPRECATED: Postgres version to use for tests",
|
|
)
|
|
|
|
|
|
def pytest_configure(config: Config):
|
|
if config.getoption("--pg-version"):
|
|
raise Exception("--pg-version is deprecated, use DEFAULT_PG_VERSION env var instead")
|