Skip to content

Commit 490e256

Browse files
authored
feat: Add pytest option to skip reliability tests by default (#7656)
* feat: Add pytest option to skip reliability tests by default * add datamodel-code-gen to dev deps * fix: update poetry.lock
1 parent 9739f82 commit 490e256

File tree

6 files changed

+163
-21
lines changed

6 files changed

+163
-21
lines changed

.github/workflows/run_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
with:
7171
args: check --fix-only
7272
- name: Run tests with pytest
73-
run: poetry run pytest tests/ --ignore=tests/reliability
73+
run: poetry run pytest tests/
7474

7575
build_poetry:
7676
name: Build Poetry

poetry.lock

Lines changed: 130 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ ipykernel = "^6.29.4"
154154
semver = "^3.0.2"
155155
pillow = "^10.1.0"
156156
litellm = { version = "^1.51.0", extras = ["proxy"] }
157+
datamodel-code-generator = "^0.26.3"
157158

158159
[tool.poetry.extras]
159160
chromadb = ["chromadb"]

tests/conftest.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import copy
33

44

5+
SKIP_DEFAULT_FLAGS = ["reliability"]
6+
57
@pytest.fixture(autouse=True)
68
def clear_settings():
79
"""Ensures that the settings are cleared after each test."""
@@ -17,3 +19,27 @@ def clear_settings():
1719
@pytest.fixture
1820
def anyio_backend():
1921
return "asyncio"
22+
23+
# Taken from: https://gist.github.com/justinmklam/b2aca28cb3a6896678e2e2927c6b6a38
24+
def pytest_addoption(parser):
25+
for flag in SKIP_DEFAULT_FLAGS:
26+
parser.addoption(
27+
"--{}".format(flag),
28+
action="store_true",
29+
default=False,
30+
help="run {} tests".format(flag),
31+
)
32+
33+
def pytest_configure(config):
34+
for flag in SKIP_DEFAULT_FLAGS:
35+
config.addinivalue_line("markers", flag)
36+
37+
def pytest_collection_modifyitems(config, items):
38+
for flag in SKIP_DEFAULT_FLAGS:
39+
if config.getoption("--{}".format(flag)):
40+
return
41+
42+
skip_mark = pytest.mark.skip(reason="need --{} option to run".format(flag))
43+
for item in items:
44+
if flag in item.keywords:
45+
item.add_marker(skip_mark)

tests/reliability/test_generated.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
_DIR_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)))
88

99

10+
@pytest.mark.reliability
1011
@pytest.mark.parametrize(
1112
"generated_case",
1213
load_generated_cases(_DIR_PATH),

tests/reliability/test_pydantic_models.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import dspy
88
from tests.reliability.utils import assert_program_output_correct, known_failing_models
99

10-
10+
@pytest.mark.reliability
1111
def test_qa_with_pydantic_answer_model():
1212
class Answer(pydantic.BaseModel):
1313
value: str
@@ -44,6 +44,7 @@ class QA(dspy.Signature):
4444

4545

4646
@pytest.mark.parametrize("module", [dspy.Predict, dspy.ChainOfThought])
47+
@pytest.mark.reliability
4748
def test_color_classification_using_enum(module):
4849
Color = Enum("Color", ["RED", "GREEN", "BLUE"])
4950

@@ -61,6 +62,7 @@ class Colorful(dspy.Signature):
6162
assert color == Color.BLUE
6263

6364

65+
@pytest.mark.reliability
6466
def test_entity_extraction_with_multiple_primitive_outputs():
6567
class ExtractEntityFromDescriptionOutput(pydantic.BaseModel):
6668
entity_hu: str = pydantic.Field(description="The extracted entity in Hungarian, cleaned and lowercased.")
@@ -106,6 +108,7 @@ class ExtractEntityFromDescription(dspy.Signature):
106108

107109

108110
@pytest.mark.parametrize("module", [dspy.Predict, dspy.ChainOfThought])
111+
@pytest.mark.reliability
109112
def test_tool_calling_with_literals(module):
110113
next_tool_names = [
111114
"get_docs",

0 commit comments

Comments
 (0)