forked from sbomify/sbomify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
60 lines (45 loc) · 1.62 KB
/
conftest.py
File metadata and controls
60 lines (45 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from pathlib import Path
import pytest
from dotenv import load_dotenv
# Register modules for assertion rewriting BEFORE they are imported
# This must be done before pytest_plugins is processed
pytest.register_assert_rewrite(
"sbomify.apps.teams.fixtures",
"sbomify.apps.sboms.tests.fixtures",
"sbomify.apps.core.tests.fixtures",
"sbomify.apps.core.tests.s3_fixtures",
"sbomify.apps.core.tests.shared_fixtures",
)
@pytest.fixture(scope="session", autouse=True)
def tests_init():
"""This only gets executed once."""
print("tests_init fixture called.")
# Load test environment variables
test_env_path = Path(__file__).parent / "test_env"
if test_env_path.exists():
print(f"Loading test environment from {test_env_path}")
load_dotenv(test_env_path)
else:
print("Warning: test_env file not found")
# Below gets called automatically by pytest-django
# setup_test_environment()
yield None
pytest_plugins = [
"sbomify.apps.core.tests.fixtures",
"sbomify.apps.core.tests.s3_fixtures",
"sbomify.apps.core.tests.shared_fixtures",
"sbomify.apps.teams.fixtures",
"sbomify.apps.sboms.tests.fixtures",
]
@pytest.fixture(autouse=True)
def _clear_cache():
"""Clear the in-memory cache between every test.
Without this, cache-backed rate limits and checkout locks leak across
tests and cause spurious 429 failures when running the full suite.
"""
from django.core.cache import cache
cache.clear()
@pytest.fixture(scope="module")
def anyio_backend():
"""Configure anyio to use asyncio backend only for async tests."""
return "asyncio"