Skip to content

test : Add shared test fixtures and split py/tests into unit and integration (PyTest - 1) - #1668

Open
Manik-Khajuria-5 wants to merge 7 commits into
fossasia:devfrom
Manik-Khajuria-5:TestingP1-1
Open

test : Add shared test fixtures and split py/tests into unit and integration (PyTest - 1)#1668
Manik-Khajuria-5 wants to merge 7 commits into
fossasia:devfrom
Manik-Khajuria-5:TestingP1-1

Conversation

@Manik-Khajuria-5

@Manik-Khajuria-5 Manik-Khajuria-5 commented Jul 31, 2026

Copy link
Copy Markdown
Member

Description

Adds a root conftest.py (10 shared fixtures) and a testutils package (fakes.py, payloads.py, http.py), and moves the existing tests into unit/ and integration/. Adds unit/test_server_utils.py and unit/test_window_builder.py, registers the unit/integration/slowmarkers, and excludes tests from find_packages.

Fixes : #1695

Motivation and Context

The same five-method setup block was copy-pasted into six test files and none of them cleaned up their mkdtemp. With no conftest.py, every new test file reinvented it and the copies had already drifted. window(), the single dispatch point from an /events payload to a rendered pane, was co indirectly through HTTP tests; it is now tested directly.

A flat py/tests also gave no answer to "where does my test go".

How Has This Been Tested?

pytest -m "not server" 227 passed, 7 subtests, on Python 3.12 and 3.13.
black py clean. No runtime code is touched, so example/demo.py
identically to a clean checkout.

Types of changes

  • Code refactor or cleanup (changes to existing code for improved readability or performance)

Checklist:

  • I adapted the version number under py/visdom/VERSION according to Semantic Versioning
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

Summary by Sourcery

Introduce shared testing utilities and fixtures, add focused unit coverage for server utilities and window builder logic, and reorganize the Python test suite into unit and integration layers with explicit markers.

Enhancements:

  • Add a testutils package (fakes, payload builders, HTTP base test case) to centralize common test helpers used across the suite.
  • Refactor storage wiring tests to use shared fakes and payload builders instead of ad hoc inline test doubles.
  • Reorganize tests into unit/ and integration/ subdirectories and document the new structure and conventions in the testing guide.
  • Exclude the tests package from distribution and update pytest configuration to expose py/tests on PYTHONPATH and register unit/integration/slow/server markers.

Documentation:

  • Expand testing.md to describe shared fixtures, testutils helpers, test placement rules, and the registered pytest markers.

Tests:

  • Add unit tests for window() and update_window() to cover pane construction and update semantics directly.
  • Add unit tests for server_utils helpers (ID escaping/extraction, password hashing, deterministic serialization) as pure-function tests.
  • Add shared pytest fixtures (env_path, stores, Application builders, handlers, sockets, offline client helpers) for hermetic, reuseable test setup.

Adds conftest.py, a testutils package, and unit tests for window().

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sorry @Manik-Khajuria-5, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@Manik-Khajuria-5 Manik-Khajuria-5 changed the title Test : Add shared test fixtures and split py/tests into unit and integration Test : Add shared test fixtures and split py/tests into unit and integration (Testing - 1) Jul 31, 2026
@sourcery-ai

sourcery-ai Bot commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Introduces shared test infrastructure (root conftest, testutils helpers), splits tests into unit vs integration, and adds direct unit coverage for visdom server utilities while tightening pytest configuration and packaging to keep tests out of the distributed package.

File-Level Changes

Change Details Files
Refactor integration tests for storage wiring to use shared test doubles and payload builders instead of inline helpers.
  • Replace inline _env helper with env_payload builder for environment data.
  • Replace ad-hoc SimpleNamespace handlers with FakeHandler for HTTP and socket wiring tests.
  • Replace local _SpyStore and _FakeSocket implementations with shared SpyStore and FakeSocket from testutils.
  • Adjust assertions to use handler.json_body(), FakeSocket helpers, and SpyStore call recording.
py/tests/integration/test_storage_wiring.py
Document the new test layout and shared fixtures and register pytest markers and pythonpath needed to use testutils without shipping tests as a package.
  • Update testing context docs to describe conftest fixtures, testutils helpers, and unit/integration directory structure.
  • Explain why py/tests has no init.py and how testutils is importable.
  • Register unit, integration, slow, and updated server markers in pytest config.
  • Extend pytest pythonpath to include py/tests while excluding tests from distribution packages via setup.py.
.agents/context/testing.md
pyproject.toml
setup.py
Add focused unit tests covering visdom.utils.server_utils pure functions and window/pane construction logic directly.
  • Add unit tests for escape_eid, extract_eid, hash_password, stringify, and recursive_order behavior.
  • Verify hash_password salt/format and a full login hashing round-trip.
  • Add extensive unit tests for window() pane construction, IDs, content types, history sliders, embeddings behavior, and defaults.
  • Add unit tests for update_window() layout merging, opt routing (including caption and legend), version bumping, and object identity.
py/tests/unit/test_server_utils.py
py/tests/unit/test_window_builder.py
Introduce shared test utilities package (testutils) with fakes, payload builders, and HTTP helper base class, and a suite-wide pytest conftest for common fixtures.
  • Create FakeSocket and FakeHandler test doubles to drive handler and socket code paths without Tornado Request objects.
  • Create SpyStore wrapper around JSONStore to record persistence calls for wiring tests.
  • Create env_payload, plot_data, window_args, and content_args helpers to standardize server payload shapes.
  • Add VisdomHTTPTestCase base class wrapping AsyncHTTPTestCase with Application setup, env_path management, and helper methods for common HTTP interactions.
  • Expose testutils helpers via init.py and add root conftest.py defining env_path/store/app/app_factory/handler/app_handler/fake_socket, offline_client, capture_send, and reset_warn_once fixtures.
py/tests/testutils/fakes.py
py/tests/testutils/http.py
py/tests/testutils/payloads.py
py/tests/testutils/__init__.py
py/tests/conftest.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@Manik-Khajuria-5 Manik-Khajuria-5 changed the title Test : Add shared test fixtures and split py/tests into unit and integration (Testing - 1) Test : Add shared test fixtures and split py/tests into unit and integration (PyTest - 1) Jul 31, 2026
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.
@Manik-Khajuria-5 Manik-Khajuria-5 changed the title Test : Add shared test fixtures and split py/tests into unit and integration (PyTest - 1) test : Add shared test fixtures and split py/tests into unit and integration (PyTest - 1) Aug 1, 2026
@Jayantparashar10

Copy link
Copy Markdown
Contributor

Please resolve conflicts

@vedansh-5 vedansh-5 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please add instructions to run the tests in CONTRIBUTING.md

@Manik-Khajuria-5 Manik-Khajuria-5 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@vedansh-5 I have added the instructions for running PyTest in CONTRIBUTING.md as mentioned

test_query.py arrived from dev at the top of py/tests with the redundant
test_ prefix. Both conventions are already documented in CONTRIBUTING.md:
tests live in unit/ or integration/, and the filename does not repeat the
word test. It is a pure parser test with no Application and no I/O, so
unit/ is the right home.
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.

Add a Python test suite (pytest) for the server and client

3 participants