Skip to content

Commit 404f364

Browse files
satcfdiCopilot
andcommitted
test: add conftest.py with shared fixtures and pytest.ini config
- Add conftest.py with reusable fixtures (test_data_dir, cfdi_ejemplos_dir, csd_dir, sample_cfdi_v40, sample_cfdi_v33, tmp_output_dir) - Register custom markers (slow, network, pac, render, create) - Add pytest.ini with testpaths and default options Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 956c3ac commit 404f364

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

pytest.ini

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[pytest]
2+
testpaths = tests
3+
python_files = test_*.py
4+
python_functions = test_*
5+
addopts = -v --tb=short

tests/conftest.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
"""Shared pytest configuration and fixtures for satcfdi tests."""
2+
3+
import os
4+
import logging
5+
6+
import pytest
7+
8+
from satcfdi.cfdi import CFDI
9+
from satcfdi.models import Signer
10+
11+
12+
TESTS_DIR = os.path.dirname(__file__)
13+
14+
15+
@pytest.fixture(scope="session")
16+
def test_data_dir():
17+
"""Return the path to the tests directory containing test data."""
18+
return TESTS_DIR
19+
20+
21+
@pytest.fixture(scope="session")
22+
def cfdi_ejemplos_dir():
23+
"""Return the path to the CFDI examples directory."""
24+
return os.path.join(TESTS_DIR, "cfdi_ejemplos")
25+
26+
27+
@pytest.fixture(scope="session")
28+
def csd_dir():
29+
"""Return the path to the CSD certificates directory."""
30+
return os.path.join(TESTS_DIR, "csd")
31+
32+
33+
@pytest.fixture
34+
def sample_cfdi_v40(cfdi_ejemplos_dir):
35+
"""Load a sample CFDI v4.0 for testing."""
36+
return CFDI.from_file(
37+
os.path.join(cfdi_ejemplos_dir, "comprobante40", "cfdv40-ejemplo.xml")
38+
)
39+
40+
41+
@pytest.fixture
42+
def sample_cfdi_v33(cfdi_ejemplos_dir):
43+
"""Load a sample CFDI v3.3 for testing."""
44+
return CFDI.from_file(
45+
os.path.join(cfdi_ejemplos_dir, "comprobante33", "cfdv33-ejemplo.xml")
46+
)
47+
48+
49+
@pytest.fixture
50+
def tmp_output_dir(tmp_path):
51+
"""Provide a temporary directory for test output files."""
52+
output = tmp_path / "output"
53+
output.mkdir()
54+
return output
55+
56+
57+
def pytest_configure(config):
58+
"""Register custom markers."""
59+
config.addinivalue_line("markers", "slow: marks tests as slow (deselect with '-m \"not slow\"')")
60+
config.addinivalue_line("markers", "network: marks tests that require network access")
61+
config.addinivalue_line("markers", "pac: marks tests that interact with PAC providers")
62+
config.addinivalue_line("markers", "render: marks tests for PDF/HTML rendering")
63+
config.addinivalue_line("markers", "create: marks tests for CFDI creation")

0 commit comments

Comments
 (0)