authentik.root.test_plugin
1import math 2from os import environ 3from ssl import OPENSSL_VERSION 4 5import pytest 6from cryptography.hazmat.backends.openssl.backend import backend 7 8from authentik import authentik_full_version 9from tests.e2e.utils import get_local_ip 10 11IS_CI = "CI" in environ 12 13 14@pytest.hookimpl(hookwrapper=True) 15def pytest_sessionstart(*_, **__): 16 """Clear the console ahead of the pytest output starting""" 17 if not IS_CI: 18 print("\x1b[2J\x1b[H") 19 yield 20 21 22@pytest.hookimpl(trylast=True) 23def pytest_report_header(*_, **__): 24 """Add authentik version to pytest output""" 25 return [ 26 f"authentik version: {authentik_full_version()}", 27 f"OpenSSL version: {OPENSSL_VERSION}, FIPS: {backend._fips_enabled}", 28 f"Local IP: {get_local_ip()} (Detected as {get_local_ip(override=False)})", 29 ] 30 31 32def pytest_collection_modifyitems(config: pytest.Config, items: list[pytest.Item]) -> None: 33 current_id = int(environ.get("CI_RUN_ID", "0")) - 1 34 total_ids = int(environ.get("CI_TOTAL_RUNS", "0")) 35 36 if total_ids: 37 num_tests = len(items) 38 matrix_size = math.ceil(num_tests / total_ids) 39 40 start = current_id * matrix_size 41 end = (current_id + 1) * matrix_size 42 43 deselected_items = items[:start] + items[end:] 44 config.hook.pytest_deselected(items=deselected_items) 45 items[:] = items[start:end] 46 print(f" Executing {start} - {end} tests")
IS_CI =
True
@pytest.hookimpl(hookwrapper=True)
def
pytest_sessionstart(*_, **__):
15@pytest.hookimpl(hookwrapper=True) 16def pytest_sessionstart(*_, **__): 17 """Clear the console ahead of the pytest output starting""" 18 if not IS_CI: 19 print("\x1b[2J\x1b[H") 20 yield
Clear the console ahead of the pytest output starting
@pytest.hookimpl(trylast=True)
def
pytest_report_header(*_, **__):
23@pytest.hookimpl(trylast=True) 24def pytest_report_header(*_, **__): 25 """Add authentik version to pytest output""" 26 return [ 27 f"authentik version: {authentik_full_version()}", 28 f"OpenSSL version: {OPENSSL_VERSION}, FIPS: {backend._fips_enabled}", 29 f"Local IP: {get_local_ip()} (Detected as {get_local_ip(override=False)})", 30 ]
Add authentik version to pytest output
def
pytest_collection_modifyitems(config: _pytest.config.Config, items: list[_pytest.nodes.Item]) -> None:
33def pytest_collection_modifyitems(config: pytest.Config, items: list[pytest.Item]) -> None: 34 current_id = int(environ.get("CI_RUN_ID", "0")) - 1 35 total_ids = int(environ.get("CI_TOTAL_RUNS", "0")) 36 37 if total_ids: 38 num_tests = len(items) 39 matrix_size = math.ceil(num_tests / total_ids) 40 41 start = current_id * matrix_size 42 end = (current_id + 1) * matrix_size 43 44 deselected_items = items[:start] + items[end:] 45 config.hook.pytest_deselected(items=deselected_items) 46 items[:] = items[start:end] 47 print(f" Executing {start} - {end} tests")