Skip to content

fix(tests): the plain-Python helper test fails in the Service image #4891

Closed

Description

@dan-petty

What happened?

tests/invariants/test_hermetic_floor.py::test_a_support_helper_called_outside_pytest_writes_nothing (added by #4857) fails in the Service Image Tests job of ci.yml (shard 5 of 6, first seen on #4872):

assert 'no pytest run is active' in 'Traceback (most recent call last):
  File "<string>", line 4, in <module>
    from tests.support.tools import link_at_pin
  ...
  File ".../tests/support/home_write_guard.py", line 45, in <module>
    import pytest
ModuleNotFoundError: No module named 'pytest'

The test starts its child with python -I. In the Service image, pytest is not in /app/.venv: the job installs the dev packages into a mounted directory and adds it with PYTHONPATH=/opt/service-test/boot and a sitecustomize. -I ignores PYTHONPATH, so the child cannot import pytest and stops before the guard. In the devcontainer and in Tests & Coverage, pytest is in the venv, so the test passes there. #4857 changed no image content, so its pull request did not run the job.

Expected behavior

The child process imports the same pytest as the test process, and the test passes in the Service image too.

Steps to reproduce

  1. Open a pull request that changes image content (for example Dockerfile), so that Service Image Tests runs.
  2. Shard 5 of 6 fails on the test above.

Proposed fix

Keep -I, and give the child the directory of the parent's pytest: pass Path(pytest.__file__).parent.parent as an argument and put it on sys.path in the child script, beside REPO_ROOT.

Activity

  1. added
    source/agent
    type/bug
    scope/tests
    status/new
    value/medium
    effort/low
    on Nov 12, 2026
  2. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor

    Intake placed this item to the backlog: intake puts every new item in the backlog. A person plans the milestones.

    • Type: type/bug. The fix prefix of the title gives the type.
    • Scope: scope/tests. The (tests) scope of the title gives the scope.
    • Priority: P2-Medium. A CI test blocks PRs that change image content, but does not affect production users.
    • Value: Medium. It unblocks CI for image-related PRs and keeps the hermetic-floor test reliable.
    • Effort: Low. The proposed fix is to pass one directory path to the child and add it to sys.path.
    • Related: fix(tests): test helpers write to the real home outside pytest #4739, which asks for a different change. Both concern the test helper guard in tests/support, but #4739 fixes helpers writing to real home while the candidate fixes a test that cannot import pytest in a child process.
  3. added
    priority/p2-medium
    owner/agent
    on Nov 12, 2026
  4. dan-petty commented on Nov 12, 2026

    @dan-petty
    OwnerAuthor

    Same failure in run 43143507971 (workflow_dispatch of Service Image Tests on the branch of #4901, 2026-11-12): shard 5 of 6 failed only tests/invariants/test_hermetic_floor.py::test_a_support_helper_called_outside_pytest_writes_nothing with ModuleNotFoundError: No module named pytest in the child Python; 4202 tests of the shard passed. The other 5 shards passed.

  5. added
    status/in-progress
    and removed
    status/new
    on Nov 12, 2026
  6. removed
    status/in-progress
    owner/agent
    on Nov 12, 2026
  7. devops-cli-service commented on Nov 12, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-12 04:08 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/lowpriority/p2-mediumscope/testssource/agenttype/bugvalue/medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions