Documentation navigation

Testing the application with pytest

Application version: 1.0.0Documentation version: 1.0.4Last technical review: 2026-10-17View Source Code on GitHub →

Written by Elena David, SEO, ORM, and AI Visibility Consultant.

Purpose

Run the executable test suite and understand what it verifies before changing application behavior.

Prerequisites

  • Python 3.11 or newer;
  • an activated virtual environment;
  • the project installed with its dev extra;
  • a terminal in the project root.

Install or refresh the development setup:

python -m pip install ".[dev]"

Run all tests

python -m pytest

pyproject.toml configures quiet output and restricts discovery to tests/. The verified result on Python 3.11.17 is:

..............................................................           [100%]
62 passed

Elapsed time varies by environment.

Run a focused test file

python -m pytest tests/test_loader.py
python -m pytest tests/test_analyzer.py
python -m pytest tests/test_reporter.py
python -m pytest tests/test_cli.py
python -m pytest tests/test_workflow.py
python -m pytest tests/test_web_importer.py
python -m pytest tests/test_dashboard.py

Run one named test with verbose output:

python -m pytest tests/test_cli.py::test_cli_generates_reports_and_summary -v

Existing coverage by behavior

Test module Verified behavior
test_loader.py Valid row conversion; empty fields; non-integer and out-of-range ratings; unsupported date text; duplicate IDs; missing columns.
test_analyzer.py ID-based new-review detection; new low-rating selection; all-current low-rating selection; invalid direct threshold.
test_reporter.py Alert CSV fields and reason; HTML escaping of review and issue content.
test_cli.py Supplied-data counts; report creation; missing-file handling; consistent filtering and labels for thresholds 1, 2, 3, and 5.
test_workflow.py Current-only metrics; optional comparison; thresholds 1 through 5.
test_web_importer.py JSON-LD, Microdata, configured selectors, article.review, missing required values, format detection, invalid URLs, restricted and private destinations, redirects, robots rules, HTTP errors, timeouts, unsupported layouts, and pages without reviews.
test_dashboard.py Uploaded CSV decoding, imported and rejected count messages, diagnostic logging, table rows, dynamic alert labels for ratings 1–5, default rating, current-only report language, downloadable payloads, restricted-import messaging, CSV switching, and session-setting preservation.

Parameterized malformed-row, threshold, URL, and network cases count as separate collected test cases.

Temporary files and test isolation

Pytest's tmp_path fixture creates an isolated directory for generated inputs and reports. Tests therefore do not overwrite the bundled data/ or reports/ files. capsys captures terminal output so CLI messages can be asserted.

Interpreting failures

A failed assertion shows expected and actual values plus the test location. Read the first application failure before addressing later failures; one behavior change can affect multiple tests.

The suite does not currently measure a coverage percentage. It also does not test every operating system, very large files, every encoding failure, or every report-write failure. Do not describe the existing suite as exhaustive.

Add a regression test

  1. Choose the module closest to the behavior.
  2. Construct the smallest input that demonstrates it.
  3. Write an assertion for the observable result.
  4. Run the focused file.
  5. Run the complete suite.
  6. Update the related documentation if public behavior changed.

Follow Maintenance and reproducibility when updating examples or generated output.