Skip to content

Commit 68d6c7d

Browse files
test: fix test failures with coverage
- Update test_to_dataframe to expect ValueError instead of TypeError - Add coverage configuration to exclude tests and temp directories - Add pytest configuration in pyproject.toml - Add root conftest.py to properly ignore temp tests - Fix path issues with test collection
1 parent 7e1fecc commit 68d6c7d

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

conftest.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Root conftest.py
2+
# This file ensures that pytest only collects tests from our tests directory
3+
# and ignores any tests in temporary directories or installed packages
4+
5+
import os
6+
import sys
7+
8+
# Add the 'src' directory to the path so imports work correctly
9+
# This ensures that the in-development code is used, not the installed version
10+
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "src")))
11+
12+
def pytest_ignore_collect(collection_path, config):
13+
"""
14+
Configure pytest to ignore certain paths when collecting tests.
15+
16+
Returns:
17+
bool: True if the path should be ignored, False otherwise.
18+
"""
19+
# Skip the temp directory
20+
if "temp/" in str(collection_path):
21+
return True
22+
23+
return False

pyproject.toml

+22
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,25 @@ disable = [
5858
"C0115", # missing-class-docstring
5959
"R0903", # too-few-public-methods
6060
]
61+
62+
[tool.pytest.ini_options]
63+
testpaths = ["tests"]
64+
python_files = "test_*.py"
65+
python_classes = ["Test*"]
66+
python_functions = ["test_*"]
67+
68+
[tool.coverage.run]
69+
source = ["src/api_to_dataframe"]
70+
omit = [
71+
"tests/*",
72+
"temp/*",
73+
"*/__init__.py",
74+
]
75+
76+
[tool.coverage.report]
77+
exclude_lines = [
78+
"pragma: no cover",
79+
"def __repr__",
80+
"raise NotImplementedError",
81+
"if __name__ == .__main__.:",
82+
]

tests/test_models_get_data.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
def test_to_dataframe():
10-
with pytest.raises(TypeError):
10+
with pytest.raises(ValueError):
1111
GetData.to_dataframe("")
1212

1313

0 commit comments

Comments
 (0)