Skip to content

test: isolate every test from the real home and guard it - #667

Merged
karhu merged 2 commits into
tnet-157/14-download-storefrom
tnet-157/14b-test-isolation
Nov 10, 2026
Merged

karhu merged 2 commits into
tnet-157/14-download-storefrom
tnet-157/14b-test-isolation

Conversation

@karhu

@karhu karhu commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

The Stack

This stack covers refactoring the internal logic of how releases are resolved during read, download & build, in particular also in the context of parent releases / parent datasets. On top of that it refactors the public TimeNet APIs and CLI interfaces around these actions, to streamline the behavior across them.

This PR

Every test runs with its own empty TIMENET_HOME.

Details

Some tests wrote into the real home folder of the developer. A build test in test_build_plan.py ran in-process without a cache folder, and the remote and S3 tests wrote control databases into ~/.cache/timenet. A TIMENET_* variable in the shell, or a .env file in the working directory, also changed the result of a test.

  • A conftest.py at the root of the repository gives each test its own empty TIMENET_HOME. It deletes every other TIMENET_* variable, and the settings do not read a .env file during the tests.
  • The connector checks run pytest from the root of the repository, so the root conftest.py isolates each connector test too.
  • The tests that cleared TIMENET_ISOLATION themselves no longer do, because the fixture clears every TIMENET_* variable.
  • Size: about 90 changed lines.

Design decisions

  • The fixture sets only TIMENET_HOME, because at this point in the stack the store, the storage and the cache all derive from it.

Breaking changes

  • None.

Stack

Changes later in the stack:

  • The fixture sets TIMENET_HOME. The PR on defaults switches it to the new variables.

Merge message

test: isolate every test from the real home and guard it

A conftest.py at the root of the repository gives each test its own
empty TIMENET_HOME and deletes every other TIMENET_* variable. So no
test writes into the home folder of the developer or depends on the
shell.

- The settings read no .env file during the tests.
- The timenet tests run as if no connector package were installed. A
  test that needs a connector installs a fake one.
- Guard tests make sure that the shell variables, a .env file and the
  settings paths of a child process cannot reach the real home.

@karhu
karhu added this pull request to stack #650 November 4, 2026 20:04
This was referenced Nov 4, 2026
@karhu
karhu force-pushed the tnet-157/14b-test-isolation branch 2 times, most recently from 621245c to b6fbf50 Compare November 5, 2026 08:16
@karhu
karhu force-pushed the tnet-157/14b-test-isolation branch from b6fbf50 to 0007693 Compare November 5, 2026 10:57
@karhu
karhu force-pushed the tnet-157/14b-test-isolation branch from 0007693 to 927ceb1 Compare November 5, 2026 14:05
@karhu
karhu force-pushed the tnet-157/14b-test-isolation branch from 9eac274 to 63ca45e Compare November 7, 2026 15:20
@karhu
karhu force-pushed the tnet-157/14b-test-isolation branch from 63ca45e to 77e446c Compare November 7, 2026 16:27
@karhu
karhu force-pushed the tnet-157/14b-test-isolation branch 2 times, most recently from 5bfac56 to f011123 Compare November 7, 2026 20:26
@karhu
karhu force-pushed the tnet-157/14b-test-isolation branch from f011123 to 589e7aa Compare November 7, 2026 22:40
@karhu
karhu force-pushed the tnet-157/14b-test-isolation branch from 589e7aa to f49df4a Compare November 9, 2026 13:56
@karhu
karhu force-pushed the tnet-157/14b-test-isolation branch 2 times, most recently from e3d3e2f to 5dfc450 Compare November 10, 2026 14:39

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM. This is a test-only change that moves the per-test TimeNet isolation into autouse fixtures.

What was reviewed:

  • The root conftest.py fixture is loaded for every package, because the only pytest config is the root pyproject.toml. It patches env_file safely: settings() builds a new TimeNetSettings on each call, so it reads the patched model_config every time.
  • Each removed TIMENET_ISOLATION delenv/setenv call relied on the default "on", so removing them changes nothing. The "setting" branch in test_build_cli.py still sets "off".
  • The .env case of the dropped test_token_defaults_to_none is now covered by the new .env guard test. The child-process guard runs with cwd=tmp_path, and the ruled-out .env concern only affects child builds outside these tests.
Extended reasoning...

The change touches only test code: a new root conftest.py, a new autouse fixture in packages/timenet/tests/conftest.py, a new guard test file, and per-test isolation lines removed from about ten test files, roughly 90 lines in all. It touches no production code and no security-sensitive surface. The removed lines either duplicate what the new fixtures do or set the default value. No CODEOWNERS file covers these paths. The only review threads are the author's own comments on a file outside this diff, so no third-party objection is open.

@karhu
karhu force-pushed the tnet-157/14b-test-isolation branch from 5dfc450 to 8fefa07 Compare November 10, 2026 15:50
@karhu
karhu removed this pull request from stack #699 November 10, 2026 15:58

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No new blocking issues. 3 optional suggestions (nits or notes on pre-existing code) were found and not posted. Nothing in this review needs a push before merging.

@karhu
karhu force-pushed the tnet-157/14b-test-isolation branch from 8fefa07 to ac56c07 Compare November 10, 2026 16:24
@karhu
karhu added this pull request to stack #772 November 10, 2026 16:24

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No new blocking issues. 2 optional suggestions (nits or notes on pre-existing code) were found and not posted. Nothing in this review needs a push before merging.

Some tests wrote into the real home of the developer. One build test
ran in-process without a cache folder, and the remote and S3 tests
wrote control databases into ~/.cache/timenet. A TIMENET_* variable
of the shell, or a .env file in the working directory, could also
change the result of a test.

A conftest.py at the root of the repository now gives each test its
own empty TIMENET_HOME. It deletes every other TIMENET_* variable,
and the settings do not read a .env file during the tests. The
connector checks of scripts/check_connectors.py run pytest from the
root of the repository, so this conftest.py isolates them too.

The timenet tests run as if no connector package were installed. The
conftest.py of packages/timenet/tests installs no builder backends for
each test. A test that needs a connector installs a fake one with
install_backends(monkeypatch, backend). So no test of the timenet
package removes the installed connectors itself.

The connector tests no longer delete TIMENET_ISOLATION themselves,
because the conftest.py deletes it before each test.

Part of TNET-157.
Shorter docstrings for the code that this change adds or changes.

Part of TNET-157.
@karhu
karhu force-pushed the tnet-157/14b-test-isolation branch from ac56c07 to ed44f4f Compare November 10, 2026 17:41
@karhu
karhu merged commit b3f692f into main Nov 10, 2026
4 of 8 checks passed
@karhu
karhu deleted the tnet-157/14b-test-isolation branch November 10, 2026 18:24
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.

2 participants