Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
*.pyc
.coverage
common.sqlite3
dist/
dist/
coverage.xml
8 changes: 5 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ optional-dependencies = { test-tools = [
"psycopg2-binary (>=2.9,<3)",
"requests",
"simplejson (>=3,<4)",

], task-processor = [
"backoff (>=2.2.1,<3.0.0)",
"django (>4,<6)",
"django-health-check",
"prometheus-client (>=0.0.16)",
], flagsmith-schemas = [
"typing_extensions",
] }
authors = [
{ name = "Matthew Elwell" },
Expand Down Expand Up @@ -68,6 +69,7 @@ dev = [
"djangorestframework-stubs (>=3.15.3, <4.0.0)",
"mypy (>=1.15.0, <2.0.0)",
"pre-commit",
"pydantic>=2.12.5",
"pyfakefs (>=5.7.4, <6.0.0)",
"pytest (>=8.3.4, <9.0.0)",
"pytest-asyncio (>=0.25.3, <1.0.0)",
Expand All @@ -77,16 +79,16 @@ dev = [
"pytest-httpserver (>=1.1.3, <2.0.0)",
"pytest-mock (>=3.14.0, <4.0.0)",
"setuptools (>=78.1.1, <79.0.0)",
"types-simplejson (>=3.20.0.20250326, <4.0.0)",
"types-python-dateutil (>=2.9.0.20250516, <3.0.0)",
"types-simplejson (>=3.20.0.20250326, <4.0.0)",
]

[build-system]
requires = ["uv_build>=0.9.17,<0.10.0"]
build-backend = "uv_build"

[tool.uv.build-backend]
module-name = ["common", "task_processor"]
module-name = ["common", "task_processor", "flagsmith_schemas"]

[tool.coverage.report]
# Regexes for lines to exclude from consideration
Expand Down
22 changes: 12 additions & 10 deletions src/common/test_tools/plugin.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
from functools import partial
from typing import Generator
from typing import TYPE_CHECKING, Generator

import prometheus_client
import pytest
from prometheus_client.metrics import MetricWrapperBase
from pyfakefs.fake_filesystem import FakeFilesystem
from pytest_django.fixtures import SettingsWrapper

from common.test_tools.types import (
AssertMetricFixture,
Expand All @@ -15,6 +11,10 @@
)
from task_processor.task_run_method import TaskRunMethod

if TYPE_CHECKING:
from pyfakefs.fake_filesystem import FakeFilesystem
from pytest_django.fixtures import SettingsWrapper


def pytest_addoption(parser: pytest.Parser) -> None:
group = parser.getgroup("snapshot")
Expand All @@ -26,12 +26,14 @@ def pytest_addoption(parser: pytest.Parser) -> None:


def assert_metric_impl() -> Generator[AssertMetricFixture, None, None]:
import prometheus_client

registry = prometheus_client.REGISTRY
collectors = [*registry._collector_to_names]

# Reset registry state
for collector in collectors:
if isinstance(collector, MetricWrapperBase):
if isinstance(collector, prometheus_client.metrics.MetricWrapperBase):
collector.clear()

def _assert_metric(
Expand All @@ -53,7 +55,7 @@ def _assert_metric(


@pytest.fixture()
def saas_mode(fs: FakeFilesystem) -> Generator[None, None, None]:
def saas_mode(fs: "FakeFilesystem") -> Generator[None, None, None]:
from common.core.utils import is_saas

is_saas.cache_clear()
Expand All @@ -65,7 +67,7 @@ def saas_mode(fs: FakeFilesystem) -> Generator[None, None, None]:


@pytest.fixture()
def enterprise_mode(fs: FakeFilesystem) -> Generator[None, None, None]:
def enterprise_mode(fs: "FakeFilesystem") -> Generator[None, None, None]:
from common.core.utils import is_enterprise

is_enterprise.cache_clear()
Expand All @@ -77,7 +79,7 @@ def enterprise_mode(fs: FakeFilesystem) -> Generator[None, None, None]:


@pytest.fixture()
def task_processor_mode(settings: SettingsWrapper) -> None:
def task_processor_mode(settings: "SettingsWrapper") -> None:
settings.TASK_PROCESSOR_MODE = True
# The setting is supposed to be set before the metrics module is imported,
# so reload it
Expand All @@ -101,7 +103,7 @@ def flagsmith_markers_marked(

@pytest.fixture(name="run_tasks")
def run_tasks_impl(
settings: SettingsWrapper,
settings: "SettingsWrapper",
transactional_db: None,
task_processor_mode: None,
) -> RunTasksFixture:
Expand Down
Empty file.
Loading