This project now uses pytest as its testing framework. The test suite captures the current production functionality to serve as baseline tests and prevent regressions.
# Run all tests
pytest tests/ -v
# Run tests with coverage report
pytest tests/ -v --cov=. --cov-report=html# Run only smoke tests (quick validation)
pytest tests/ -v -m smoke
# Run only unit tests
pytest tests/ -v -m unit
# Run only integration tests
pytest tests/ -v -m integration# Test utility functions
pytest tests/unit/test_utils.py -v
# Test error recording functionality
pytest tests/integration/test_record_error.py -v
# Run smoke tests
pytest tests/test_smoke.py -vtests/
├── conftest.py # Shared fixtures and pytest configuration
├── test_smoke.py # Smoke tests for quick validation
├── unit/
│ └── test_utils.py # Unit tests for utility functions
├── integration/
│ └── test_record_error.py # Integration tests for error recording
├── api/
│ └── [future API tests]
└── pipeline/
└── [future pipeline tests]
- Purpose: Quick validation that the system is in a working state
- Run time: < 1 second
- Coverage: Verifies all key modules can be imported and basic functions are callable
- Use case: Pre-deployment checks, CI/CD smoke test stage
- Purpose: Test individual functions in isolation
- Coverage: Current behavior of:
- DAC time/date conversions
- Price formatting
- UPC code conversions
- Check digit calculations
- String-to-integer conversion
- Note: Tests capture current production behavior exactly
- Purpose: Test interaction between modules
- Coverage: Error recording functionality across file and threaded modes
All fixtures are defined in conftest.py:
Creates a temporary directory that's cleaned up after the test.
def test_something(temp_dir):
# temp_dir is a path to a temporary directory
file_path = os.path.join(temp_dir, "test_file.txt")Creates a simple text file for testing.
def test_something(sample_file):
# sample_file is a path to a file containing "test content\n"
with open(sample_file) as f:
content = f.read()Creates a sample CSV file with headers and one data row.
def test_something(sample_csv_file):
# sample_csv_file is a path to a CSV file
passCreates a sample EDI file for testing conversions.
def test_something(sample_edi_file):
# sample_edi_file is a path to an EDI format file
passReturns the project root directory as a Path object.
def test_something(project_root):
# project_root is the batch-file-processor directory
passimport pytest
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import your_module
@pytest.mark.unit
class TestYourModule:
"""Tests for your_module."""
def test_something(self):
"""Test description."""
result = your_module.function_name()
assert result == expected_value@pytest.mark.unit
def test_with_fixture(temp_dir, sample_file):
"""Test using multiple fixtures."""
# Use both temp_dir and sample_file
assert os.path.exists(sample_file)
assert os.path.isdir(temp_dir)38 total tests passing:
-
Smoke Tests: 10 tests
- Module availability checks
- Function callability verification
- Project structure validation
-
Unit Tests: 24 tests
TestDacStrIntToInt: 4 testsTestConvertToPrice: 3 testsTestDactimeFromDatetime: 3 testsTestDatetimeFromDactime: 3 testsTestDatetimeFromInvtime: 2 testsTestDactimeFromInvtime: 2 testsTestCalcCheckDigit: 1 testTestConvertUPCEToUPCA: 6 tests
-
Integration Tests: 4 tests
TestRecordErrorBasic: 4 tests (file and threaded logging)
Configures pytest behavior:
- Test discovery patterns
- Test output format (verbose by default)
- Warnings disabled
- Configurable via
pytest.iniin the project root
pytest tests/ -v --cov=. --cov-report=html --cov-report=termThis generates an HTML coverage report in htmlcov/index.html.
# Fast smoke tests only (ideal for pre-commit)
pytest tests/ -m smoke -v
# All tests except slow
pytest tests/ -m "not slow" -vIf pytest isn't finding your tests:
- Ensure files start with
test_or end with_test.py - Check that test functions start with
test_ - Verify
conftest.pyis in the tests directory
If you get import errors:
- Ensure
conftest.pyexists in the tests directory - Check that the main modules are in the project root (same level as tests/)
- Use the fixture-based path setup shown in test examples
Add this to your test file:
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))These test categories are ready for expansion:
- tests/api/: API endpoint tests
- tests/pipeline/: Full pipeline integration tests
- tests/api/: Batch processing tests
Add test files to these directories as needed and mark them appropriately with @pytest.mark.unit, @pytest.mark.integration, @pytest.mark.slow, etc.