TS001: HasTestsDirectory

Overview

Property Value
ID TS001
Name HasTestsDirectory
Group tests
Severity WARNING

Description

Checks that a tests directory exists in the package root.

Having tests is important for:

  • Ensuring code correctness
  • Preventing regressions
  • Documenting expected behavior
  • Enabling confident refactoring

What it checks

The check looks for either of these directories in the package root:

  • tests/
  • test/

How to fix

Create a tests/ directory and add at least one test file:

mkdir tests
touch tests/__init__.py

Create a basic test file tests/test_example.py:

def test_example():
    """Example test to verify pytest works."""
    assert 1 + 1 == 2

Setting up pytest

Add pytest to your dev dependencies:

[project.optional-dependencies]
dev = [
    "pytest>=8.0.0",
]

Configure pytest in pyproject.toml:

[tool.pytest.ini_options]
testpaths = ["tests"]

Run tests:

pytest

Test structure

Recommended directory structure:

my-package/
├── src/
│   └── my_package/
│       └── __init__.py
├── tests/
│   ├── __init__.py
│   ├── conftest.py
│   ├── test_core.py
│   └── test_utils.py
└── pyproject.toml

Why WARNING severity?

This check is a WARNING rather than an ERROR because:

  • Some packages (e.g., type stubs) may not need tests
  • Early-stage packages may not have tests yet
  • Tests might be in a separate repository

However, we strongly recommend having tests for any production package.

Configuration

Skip this check

[tool.pycmdcheck]
skip = ["TS001"]

CLI

pycmdcheck --skip TS001

Treat as error

If you want this check to fail CI:

[tool.pycmdcheck]
error_on = "warning"