Skip to content

Adopt pytest for the existing test suite (discovery + fixtures) #4

Description

@bernalde

Goal

Make the existing test suite discoverable and runnable by pytest without changing test logic or reformatting source code. This is the foundation for restoring CI (part of #3).

Current state

  • Two test modules exist, both unittest.TestCase-based and run only via python path/to/file.py:
    • tests/integration/reactor_tests.pyPlugFlowReactorTests (test_mole_conc, test_temperature), data-driven from tests/integration/data/pfr_test_expected_conc_*.csv (51 files).
    • tests/Flowsheet/flowsheet_tests.pyTestFlowsheets with 4 multi-unit scenarios, data in tests/Flowsheet/data/.
  • No conftest.py, no pytest.ini, no tests/__init__.py.
  • Test data is loaded from relative paths, so tests fail when invoked from another working directory.
  • unittest.TestCase discovers fine under pytest, so no rewrite is required.

Tasks

  • Add tests/__init__.py (and tests/integration/__init__.py, tests/Flowsheet/__init__.py as needed).
  • Add tests/conftest.py with fixtures:
    • data_path → resolves Path(__file__).parent / ... so tests are CWD-independent.
    • assimulo_available → returns whether assimulo imports; used to skip integration tests gracefully.
  • Add pytest.ini (or [tool.pytest.ini_options] in pyproject.toml) with:
    • testpaths = tests, discovery for *_tests.py / test_*.py.
    • markers: slow, integration, unit, assimulo.
    • a sane default timeout and warning filters.
  • Update the two test modules to resolve data files via the data_path fixture / Path(__file__) instead of relative strings (minimal, surgical change only).
  • Mark assimulo-dependent tests with @pytest.mark.assimulo and auto-skip when unavailable.

Acceptance criteria

  • pytest tests/ -v collects and runs both modules from any working directory.
  • Assimulo-dependent tests are skipped (not errored) when assimulo is absent.
  • No source files outside tests/ are modified; no black/formatting changes.

Reference

Reusable scaffolding existed in reverted PR #106 (pytest.ini, tests/conftest.py at commit 599ffb3) — adapt it, but keep this PR scoped to test discovery only.


Upstream PR

Wave 1 — strong first candidate. Test-only, touches no source files; ideal low-risk PR to open directly against CryPTSys/PharmaPy master. See the upstream strategy in #3.


Reverted PR provenance

This issue is part of the selective re-introduction of useful infrastructure from the reverted upstream work:

Implementation should stay small and reviewable, avoid repo-wide formatting, and preserve traceability through one focused PR per issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:testingTest discovery, fixtures, coverage, and test strategystatus:plannedPlanned roadmap or maintenance work, not a verified bug reporttestingTest suite and coverage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions