Skip to content

MacHu-GWU/sqlalchemy_upsert_kit-project / .claude/skills/pywf-oss-base

pywf-oss-base

Flagged

Shared conventions, references, and scripts of the pywf-oss skills for pywf open-source Python libraries: setup, layout, code style, tests, user docs and the agent skills that hold API and maintenance knowledge, CI and hosting, release, dependencies, and secrets. Load it before ad-hoc work on modules, tests, or docs in such a repo, for a question about these conventions, or when unsure which pywf-oss skill fits a job.

FileKindSize
SKILL.mdskill md6.5 KB
assets/community-skills.tomlconfig2.4 KB
assets/notebook-page-template.ipynbother1.1 KB
assets/raw-rst-cell.jsonconfig255 B
references/00-authoring-references.mdmarkdown6.3 KB
references/01-secrets.mdmarkdown3.0 KB
references/02-machine-setup.mdmarkdown3.2 KB
references/03-mise.mdmarkdown2.1 KB
references/04-python-versions.mdmarkdown1.8 KB
references/05-uv-dependencies.mdmarkdown2.0 KB
references/06-ruff.mdmarkdown1.9 KB
references/07-repo-layout.mdmarkdown2.3 KB
references/08-package-files.mdmarkdown3.9 KB
references/09-code-style.mdmarkdown5.6 KB
references/10-test-layout.mdmarkdown4.1 KB
references/11-test-writing.mdmarkdown2.1 KB
references/12-coverage.mdmarkdown1.1 KB
references/13-sphinx.mdmarkdown5.6 KB
references/14-docfly.mdmarkdown2.2 KB
references/15-furo.mdmarkdown1.4 KB
references/16-sphinx-design.mdmarkdown5.8 KB
references/17-nbsphinx.mdmarkdown5.0 KB
references/18-knowledge-channels.mdmarkdown3.8 KB
references/19-github-actions.mdmarkdown3.7 KB
references/20-codecov.mdmarkdown1.3 KB
references/21-readthedocs.mdmarkdown1.7 KB
references/22-versioning-and-changelog.mdmarkdown3.0 KB
references/23-release.mdmarkdown1.3 KB
references/24-dependency-upgrades.mdmarkdown3.2 KB
references/25-python-release-cycle.mdmarkdown1.4 KB
references/26-community-skills.mdmarkdown5.0 KB
references/27-skill-family-workflow.mdmarkdown6.5 KB
scripts/check_doc_xrefs.pyscript3.4 KB
scripts/check_one_import_per_line.pyscript4.2 KB
scripts/check_skill_family.pyscript6.5 KB
scripts/check_test_layout.pyscript6.2 KB
scripts/install_community_skill.pyscript8.6 KB
scripts/update_skill_index.pyscript4.1 KB

references/10-test-layout.md

View on GitHub
---
description: "The test suite structure: the source-to-test path mapping with directory-prefixed names, files with no test, the run_cov_test block, all.py per tested folder, the layout check script, the pytest config, and how to run tests. Read when working out a test file's path, creating or moving test files, or running tests."
---

# Test Layout

Tests use pytest. Every source module has exactly one test file, which also runs on its own as a script that reports the coverage of just its module.

---

## 1. Source-to-test mapping

The `tests/` tree mirrors the `<package_name>/` tree. Directory names stay the same, and **each file name is prefixed with its full directory path**:

| Source | Test file |
| :--- | :--- |
| `<package_name>/api.py` | `tests/test_api.py` |
| `<package_name>/module_name.py` | `tests/test_module_name.py` |
| `<package_name>/subpackage/module_name.py` | `tests/subpackage/test_subpackage_module_name.py` |
| `<package_name>/a/b/module_name.py` | `tests/a/b/test_a_b_module_name.py` |
| `<package_name>/a/_private.py` | `tests/a/test_a__private.py` |
| `<package_name>/a/b/` (a subpackage) | `tests/a/b/all.py` |
| `<package_name>/` (the whole package) | `tests/all.py` |

- **Why the prefix:** pytest's default import mode needs unique test module basenames. Without it, `tests/a/test_api.py` and `tests/b/test_api.py` collide, and the whole run fails with "import file mismatch".
- **No test file for** `__init__.py` or any file excluded from coverage in `08-package-files.md` section 8.
- `tests/` subfolders have no `__init__.py`.
- An occasional exception, such as one test file for two tiny modules, is fine with a comment saying why.

### The layout check

```bash
python ${CLAUDE_SKILL_DIR}/../pywf-oss-base/scripts/check_test_layout.py --project_root .
```

It lists missing test files, orphan test files that map to no module, and `run_cov_test` blocks whose module path does not match the file. Add `--source <source_path>` to print the expected test path and module for one source file.

---

## 2. The `run_cov_test` block

Every test file ends with this block:

```python
if __name__ == "__main__":
    from <package_name>.tests import run_cov_test

    run_cov_test(
        __file__,
        "<package_name>.subpackage.module_name",
        preview=False,
    )
```

- The import sits inside the `if __name__ == "__main__":` block.
- **One argument per line, with a trailing comma,** so the user can switch `preview=False` to `preview=True` (open the HTML report in a browser) by editing one line.
- The second argument is the dotted module path of the source file this test file maps to.

---

## 3. `all.py`: one per tested folder

Every `tests/` folder that mirrors a subpackage has an `all.py`, which runs every test in the folder and measures coverage on the whole subpackage:

```python
# -*- coding: utf-8 -*-

if __name__ == "__main__":
    from <package_name>.tests import run_cov_test

    run_cov_test(
        __file__,
        "<package_name>.subpackage",
        is_folder=True,
        preview=False,
    )
```

- `is_folder=True` makes pytest collect the folder of `__file__` instead of the single file.
- `tests/all.py` covers the whole package (`"<package_name>"`).
- `all.py` has no test functions and no `test_` prefix, so the full suite never collects it.

---

## 4. pytest configuration

`pyproject.toml` has a native `[tool.pytest]` table (pytest 9+) with `testpaths = ["tests"]`, and optional settings as comments. Keep it small: `run_cov_test` and the mise tasks pass their own options.

---

## 5. Running tests

| Goal | Command |
| :--- | :--- |
| One module, with its own coverage | `.venv/bin/python tests/subpackage/test_subpackage_module_name.py` |
| One subpackage, with its coverage | `.venv/bin/python tests/subpackage/all.py` |
| Everything, with coverage | `mise run cov` |
| Everything, fast | `mise run test` |
| An ad-hoc selection | `.venv/bin/pytest tests/subpackage -k keyword` |

While developing a module, run its own test file. Before finishing, run `mise run cov`.

---

## 6. Other test folders

Tests against real external services go in `tests_int/`, load tests in `tests_load/`. Both follow the same mapping rules.
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 471kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall