-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(py): Rename CLI arg for pytest plugin from --output to --langsmit…
…h-output to avoid conflict (#1482) Copy of #1472, since something is wrong with our secrets injection for contributors in CI --------- Co-authored-by: Ryan Echols <[email protected]> Co-authored-by: Ryan Echols <[email protected]>
- Loading branch information
1 parent
bd7dfb3
commit 130f87d
Showing
3 changed files
with
122 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import os | ||
|
||
import pytest | ||
|
||
from langsmith import testing as t | ||
|
||
|
||
@pytest.mark.skipif( | ||
not os.getenv("LANGSMITH_TRACING"), | ||
reason="LANGSMITH_TRACING environment variable not set", | ||
) | ||
@pytest.mark.langsmith | ||
@pytest.mark.parametrize("c", list(range(10))) | ||
async def test_addition_single(c): | ||
x = 3 | ||
y = 4 | ||
t.log_inputs({"x": x, "y": y, "c": c}) | ||
|
||
expected = 7 + c | ||
t.log_reference_outputs({"sum": expected}) | ||
|
||
actual = x + y + c | ||
t.log_outputs({"sum": actual}) | ||
|
||
t.log_feedback(key="foo", score=1) | ||
|
||
assert actual == expected | ||
|
||
|
||
async def my_app(): | ||
return "hello" | ||
|
||
|
||
@pytest.mark.skipif( | ||
not os.getenv("LANGSMITH_TRACING"), | ||
reason="LANGSMITH_TRACING environment variable not set", | ||
) | ||
@pytest.mark.langsmith | ||
async def test_openai_says_hello(): | ||
# Traced code will be included in the test case | ||
text = "Say hello!" | ||
response = await my_app() | ||
t.log_inputs({"text": text}) | ||
t.log_outputs({"response": response}) | ||
t.log_reference_outputs({"response": "hello!"}) | ||
|
||
# Use this context manager to trace any steps used for generating evaluation | ||
# feedback separately from the main application logic | ||
with t.trace_feedback(): | ||
grade = 1 if "hello" in response else 0 | ||
t.log_feedback(key="llm_judge", score=grade) | ||
|
||
assert "hello" in response.lower() | ||
|
||
|
||
@pytest.mark.skipif( | ||
not os.getenv("LANGSMITH_TRACING"), | ||
reason="LANGSMITH_TRACING environment variable not set", | ||
) | ||
@pytest.mark.xfail(reason="Test failure output case") | ||
@pytest.mark.langsmith(output_keys=["expected"]) | ||
@pytest.mark.parametrize( | ||
"a, b, expected", | ||
[ | ||
(1, 2, 3), | ||
(3, 4, 7), | ||
], | ||
) | ||
async def test_addition_parametrized(a: int, b: int, expected: int): | ||
t.log_outputs({"sum": a + b}) | ||
assert a + b != expected | ||
|
||
|
||
@pytest.mark.skipif( | ||
not os.getenv("LANGSMITH_TRACING"), | ||
reason="LANGSMITH_TRACING environment variable not set", | ||
) | ||
@pytest.mark.langsmith | ||
@pytest.mark.parametrize("a,b", [[i, i] for i in range(20)]) | ||
def test_param(a, b): | ||
t.log_outputs({"sum": a + b}) | ||
t.log_reference_outputs({"sum": a + b}) | ||
assert a + b == a + b |