Skip to content

Tests(py): add local pytest runtime foundation#10498

Draft
nmanovic wants to merge 5 commits intov3-pr3-psycopgfrom
v3-pr4a-runtime-foundation
Draft

Tests(py): add local pytest runtime foundation#10498
nmanovic wants to merge 5 commits intov3-pr3-psycopgfrom
v3-pr4a-runtime-foundation

Conversation

@nmanovic
Copy link
Copy Markdown
Contributor

Summary

This is PR 5 in the split series.

Base: v3-pr3-psycopg

This PR introduces the pytest-managed local runtime foundation while preserving the existing kube/minikube behavior through the legacy path.

Scope:

  • move pytest runtime bootstrap to explicit session lifecycle management
  • add explicit local lifecycle control via --infra
  • add runtime run-id/artifact directory management
  • add startup version sanity checks
  • keep kube compatibility intact through shared.fixtures.init

Non-goals for this PR:

  • no infra profiles
  • no parallel runtime
  • no DB/Redis fast restore
  • no runtime URL rewriting
  • no kube redesign

Main changes

  • move pytest configuration to repo root
  • replace wildcard fixture bootstrapping in tests/python/conftest.py with explicit runtime setup
  • add tests/python/infra/* foundation modules for runtime config, health checks, lifecycle helpers, version checks, and local instance management
  • preserve fixed local ports intentionally in this PR to avoid changing existing API payload/base URL expectations
  • keep generic shared request helpers on pytest/runtime-level timeout policy, documented with targeted lint suppression
  • retain legacy kube behavior in tests/python/shared/fixtures/init.py for compatibility until the later kube PR

Validation

Passed:

  • helm lint helm-chart
  • helm template cvat helm-chart
  • helm template smoke helm-chart --set cvat.opa.composeCompatibleServiceName=false
  • helm template smoke helm-chart --set cvat.opa.composeCompatibleServiceName=false --set cvat.opa.probePath=/health
  • py_compile
  • black --check
  • isort --check
  • pylint on touched files (10.00/10)
  • pytest tests/python/ --collect-only
  • local lifecycle commands:
    • --infra=up
    • --infra=down
    • --infra=restore-db
    • --infra=build-images
  • representative local REST/CLI/SDK smokes
  • full Python suite:
    • 2178 passed, 20 skipped, 1 xfailed, 1 warning
    • 26:28
  • Django unit tests:
    • 412 tests
    • OK (skipped=58)
    • 10:48
  • representative kube compatibility smoke through the preserved legacy path

Important note

During validation I trimmed an earlier version of this PR that introduced dynamic local ports too early. That caused broad REST expectation breakage because many test payloads still assume http://localhost:8080.

This PR now intentionally preserves the legacy fixed-port local contract. Dynamic runtime URL/port work will be introduced later, in the dedicated runtime-profile PR where the test data and expectations are updated together.

@nmanovic nmanovic requested a review from zhiltsov-max as a code owner April 19, 2026 07:17
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3bc10fb4fa

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +123 to +127
docker_host = os.environ.get("DOCKER_HOST", "")
if docker_host.startswith("unix://"):
candidate = docker_host.removeprefix("unix://")
if os.path.exists(candidate):
return candidate
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor non-unix Docker hosts for container discovery

The new container discovery path only treats DOCKER_HOST as valid when it starts with unix://, then falls back to hardcoded local socket paths; environments that use DOCKER_HOST=tcp://... (or a non-socket Docker context) will hit FileNotFoundError("Docker socket not found") even though normal docker commands could still work. Because session startup now depends on this discovery (running_containers() / project_containers_running()), local pytest runs fail early in those setups.

Useful? React with 👍 / 👎.

Comment thread tests/python/conftest.py
Comment on lines +130 to +132
if platform == "kube":
legacy_init.session_start(session)
if should_run_version_check:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject local-only --infra modes when platform is kube

pytest_sessionstart parses --infra, but for --platform=kube it unconditionally calls legacy_init.session_start(session) and never validates that the selected infra mode is supported. This means commands like --platform=kube --infra=down/up/restore-db are accepted but silently run the normal kube startup path instead of the requested lifecycle action, which is misleading and can trigger unintended test execution.

Useful? React with 👍 / 👎.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@nmanovic nmanovic force-pushed the v3-pr4a-runtime-foundation branch from 3bc10fb to f2c8e67 Compare April 21, 2026 07:17
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f2c8e676bf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +614 to +618
stack_ok, reason = project_stack_compatible(
project_name,
expected_db_port=project_cfg.host_db_port,
expected_redis_inmem_port=project_cfg.host_redis_inmem_port,
expected_redis_ondisk_port=project_cfg.host_redis_ondisk_port,
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Check Traefik port before reusing an existing stack

project_stack_compatible() is only given DB/Redis expectations here, but startup URL selection is driven by CVAT_BASE_URL (from the expected HTTP port). In --infra=reuse and auto mode, a stack with mismatched Traefik host port can be treated as compatible, then wait_for_services() polls the wrong URL and startup times out instead of rejecting/recreating the stack. Include HTTP (and related service endpoint) port compatibility in this gate.

Useful? React with 👍 / 👎.

@nmanovic nmanovic force-pushed the v3-pr4a-runtime-foundation branch from f2c8e67 to 0a878d3 Compare April 21, 2026 12:47
@nmanovic nmanovic marked this pull request as draft April 21, 2026 12:48
@nmanovic nmanovic force-pushed the v3-pr4a-runtime-foundation branch from 0a878d3 to ce7a4fe Compare April 21, 2026 12:51
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0a878d3976

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +39 to +43
group._addoption(
"--infra",
action="store",
default=RuntimeInfraConfig.get_default_infra_mode(),
choices=RuntimeInfraConfig.get_infra_modes(),
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve legacy lifecycle CLI flags in option parser

By only registering --infra here, pytest no longer accepts legacy flags like --start-services, --stop-services, --rebuild, and --keep-data. Existing repo automation still invokes those flags (for example, .github/workflows/schedule.yml runs pytest tests/python/ --stop-services on lines 149 and 153), so those jobs now fail at argument parsing before tests/teardown logic runs. Please keep temporary aliases to the new --infra modes or migrate all in-repo callers in the same change.

Useful? React with 👍 / 👎.

Comment on lines +169 to +173
expected = {
f"{project_name}_cvat_server_1",
f"{project_name}_cvat_db_1",
f"{project_name}_traefik_1",
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Require worker containers before reusing local stack

This running-stack check only requires cvat_server, cvat_db, and traefik, and _run_local_lifecycle() uses it to skip start_services() in --infra=auto/reuse. If one or more worker containers are missing, the run is still treated as reusable, but background jobs (import/export/annotation/webhooks) will not be processed and related tests can hang or fail. Include required worker services in the readiness set (or always run docker compose up -d) before considering the stack reusable.

Useful? React with 👍 / 👎.

@nmanovic nmanovic force-pushed the v3-pr4a-runtime-foundation branch from ce7a4fe to 29cef23 Compare April 21, 2026 15:30
@nmanovic nmanovic force-pushed the v3-pr4a-runtime-foundation branch from 29cef23 to 360c5ac Compare April 21, 2026 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant