Nexent Python unit tests
Paths below are relative to the repository root.
- Identify the unit and behavior. Inspect neighboring tests,
test/conftest.py, andtest/pytest.inibefore changing fixture/import setup. - Use pytest exclusively, pytest assertions, fixtures, and
pytest-mock. Files/functions start withtest_; test classes start withTest. Keep files below 500 lines or split by feature usingtest_<module>_<feature>.py; split package directories include__init__.py. - Import the unit and necessary test helpers. Mock collaborators rather than exercising external interfaces/clients/services. Patch the fully qualified lookup site determined from actual imports, not the dependency's definition module.
For example, if backend.services.example_service imports fetch using from provider import fetch, patch backend.services.example_service.fetch. If the runtime loads the module as services.example_service, use that actual path. Do not copy an unrelated service path from an example.
- Isolate external I/O and APIs. Reset mutable state with fixtures; use
autouse=Truewhen every test in a scope requires it. Do not mock away the behavior being asserted. - Cover changed success/error flows and boundaries with specific observable assertions. Use
side_effectfor collaborator errors,@pytest.mark.parametrizefor variants, and@pytest.mark.asynciofor async tests. Async collaborators need awaitable mocks. - Order imports as standard library, third-party, then project; write comments/docstrings in English.
- Run narrow tests from the root with a working backend environment, such as
pytest test/backend/apps/test_agent_app.py -v. Broaden when needed;python test/run_all_test.pyis the existing broad runner.
Report commands, results, and environment failures. Unit-test isolation does not replace live-service functional checks or real-model acceptance.