test hygiene: track stray suites, cover shared utils, atomic env writes (PyTest - 4) - #1672
Open
Manik-Khajuria-5 wants to merge 26 commits into
Open
test hygiene: track stray suites, cover shared utils, atomic env writes (PyTest - 4)#1672Manik-Khajuria-5 wants to merge 26 commits into
Manik-Khajuria-5 wants to merge 26 commits into
Conversation
Adds conftest.py, a testutils package, and unit tests for window().
AsyncHTTPTestCase is a unittest.TestCase, and pytest will not inject fixtures into those. Run the Application on a background event loop instead and talk to it with requests, which is already a runtime dependency, so HTTP tests can be plain functions.
Lands the window lifecycle file as plain pytest functions on the visdom_server fixture, dropping the per-file setUp block and the temp directory it never cleaned up.
Collapses the repeated plot-trace and opts assertions into parametrized tables, so each case reports separately instead of hiding behind the first failure.
The reload case now builds its second Application from the app_factory fixture, which shares env_path with visdom_server, instead of hand-rolling one against a leaked temp directory.
The update-into-a-missing-env case asserted 'status is 200 or 500', which could not fail. It now pins the actual behaviour: 200 with 'win does not exist'.
register_window took the index from len(env), so closing any window but the last produced a duplicate index and the pane order went undefined after a reload. Use max(i) + 1, which is what the undo path already does.
Three validation checks used a bare assert, so an invalid request came back as a 500 and, under python -O, was skipped entirely: forking an unknown env then raised KeyError and a named trace update read past the data it was given. Raise HTTPError(400) like the other checks do.
Places the two test files dev added into the new layout, and points the new storage-wiring test at env_payload: it called the local _env helper this branch had already replaced, which merged cleanly and then failed.
Brings in dev along with the layout placement and the env_payload fix made on the PR-1 branch. D1 and D2 both survive the auto-merge of server_utils.py and web_handlers.py.
Replaces the background event loop and requests session with the AsyncHTTPTestCase base class from PR-1, which already runs the app in-process on an ephemeral port. The four integration files become TestCase subclasses; pytest still collects and marks them.
first/second read as two windows; they are the id returned by each call, which is the same id both times. Also assert only one pane exists.
The guidance still said VisdomHTTPTestCase was scheduled for replacement by a background-loop fixture. Record the opposite, and the consequences for anyone writing an HTTP test: no fixtures, no parametrize, share via a base class.
Both halves now run off VisdomHTTPTestCase instead of their own fixture block.
The three cap tables collapse onto parametrize; the file was untracked until now.
Guard the missing-point check behind a numeric test, and stop indexing data and traces past their length when an update supplies fewer entries than the plot.
It was the one history pane that grew without bound.
Contributor
There was a problem hiding this comment.
Sorry @Manik-Khajuria-5, your pull request is larger than the review limit of 150000 diff characters
Contributor
Reviewer's GuideRefactors and expands the Python test suite structure (unit vs integration, shared testutils) while adding durability and edge-case coverage for JSONStore/env handling and UpdateHandler, plus introducing atomic env writes and new memory caps in server defaults and handlers. Sequence diagram for atomic JSONStore env writessequenceDiagram
actor Client
participant ForkEnvHandler as ForkEnvHandler
participant JSONStore as JSONStore
participant OS as os
Client->>ForkEnvHandler: POST /env/fork
ForkEnvHandler->>ForkEnvHandler: copy.deepcopy(handler.state[prev_eid])
ForkEnvHandler->>JSONStore: save_env(eid, handler.state[eid])
JSONStore->>JSONStore: serialize_env(eid, env_data)
JSONStore->>JSONStore: _hash_path(eid)
JSONStore->>JSONStore: _atomic_write(path, payload)
JSONStore->>OS: open(path + ".tmp", "w")
OS-->>JSONStore: write(payload)
JSONStore->>OS: os.replace(tmp, path)
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Manik-Khajuria-5
requested review from
marcoag,
mariobehling,
norbusan,
tonypzy and
vedansh-5
August 1, 2026 12:03
Manik-Khajuria-5
requested review from
Jayantparashar10,
Saksham-Sirohi and
rajnisht7
August 1, 2026 12:03
Removing a heatmap names no trace and posts no data, so the shortcut for opts-only updates returned before the delete branch and left the plot up.
8 tasks
8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Test-suite hygiene plus one durability fix in
JSONStore.Moved two untracked suites into the collected tree: build verification (
integration/test_build_verification.py) and t-SNE (unit/test_tsne.py).Added
unit/test_shared_utils.py; extendedunit/test_data_model.pywithLazyEnvData's mapping and deep-copy behaviour.Fix:
serialize_envwrote straight to the target file, so an interrupted save truncated the old environment andload_envreported it as empty. Writes now stage into<path>.tmpandos.replace;save_undoshares the same helper.Moved
visual_check.pytoexample/manual/it needs a live server and a human eye, so it isn't collectable. Rule documented in.agents/context/testing.md.Fixes : #1695
Integration note
This PR should be merged after #1671 , as it depends on the lower-layer changes introduced there.
Motivation and Context
Two test files existed but were never collected, so that code was untested in CI. The atomic write closes a real data-loss window on env save.
How Has This Been Tested?
pytest py/testson Python 3.12: 593 passed (174 in the touched files). No new dependencies; all tests hermetic.Types of changes
Checklist:
py/visdom/VERSIONaccording to Semantic VersioningSummary by Sourcery
Strengthen visdom’s persistence and update semantics while formalizing the Python test layout into unit and integration suites with shared test utilities and manual examples.
New Features:
Bug Fixes:
Enhancements:
Build:
Documentation:
Tests: