Testing¶
Test Categories¶
Dry-Run Tests¶
Test tools without the rendering engine by passing cmd=None. Every tool should handle this:
def test_my_tool_dry_run():
from tools.mygroup.mytool import run
result = run(None, "arg1", "arg2")
assert result is not None
Mock Tests¶
Use the mock_cmd fixture for testing rendering interactions:
def test_my_tool_mock(mock_cmd):
from tools.mygroup.mytool import run
result = run(mock_cmd, "protein")
mock_cmd.show.assert_called_once()
Integration Tests¶
Require the full rendering engine — auto-skipped in CI:
@pytest.mark.integration
def test_my_tool_real():
import codemol
# ... test with full rendering engine
Key Fixtures¶
Defined in tests/conftest.py:
| Fixture | Scope | Description |
|---|---|---|
all_tools |
Session | Full tool registry via discover_tools() |
mock_cmd |
Function | MagicMock with standard rendering return values |
reset_measurement_registry |
Function (autouse) | Clears measurement registry |
reset_selection_overrides |
Function (autouse) | Clears alias overrides |
mock_cmd Default Returns¶
cmd.count_atoms.return_value = 10
cmd.distance.return_value = 3.5
cmd.angle.return_value = 109.5
cmd.get_dihedral.return_value = -60.0
cmd.get_names.return_value = []
cmd.get_object_list.return_value = ["test_obj"]
cmd.get_model.return_value = MagicMock(atom=[])
Running Tests¶
# All non-integration tests
pytest tests/ -v
# Specific test file
pytest tests/test_tools.py -v
# Specific test
pytest tests/test_tools.py::test_distance -v
# With coverage
pytest tests/ --cov=codemol --cov=tools
# Integration tests only (needs rendering engine)
pytest tests/ -v -m integration
Test Data¶
Test data lives in tests/:
tests/
├── conftest.py # Fixtures
├── docking/
│ ├── docking_amazon/ # GOLD docking results
│ └── docking_brazil/ # GOLD docking results
└── projects/ # Sample project files
Writing Good Tests¶
Test the contract, not the implementation
Test that run() returns the right string and calls the right rendering methods — don't test internal helper functions.
Use dry-run for smoke tests
A dry-run test catches import errors, missing dependencies, and argument mismatches without needing the rendering engine.
Reset shared state
The autouse fixtures handle measurement registry and selection overrides. If your tool uses other shared state, add a reset fixture.