Skip to content

Commit 2dd8931

Browse files
committed
elastic-opentelemetry-instrumentation-openai: add openai integration tests
This adds a bunch of integration tests hitting openai. This requires setting a variable `OPENAI_API_KEY` in github secrets. Tests themselves are a copy of the recorded ones asserting values from the response data. Integration tests are not run by default and can be called with `pytest --integration-tests`
1 parent e24e1f1 commit 2dd8931

File tree

6 files changed

+562
-6
lines changed

6 files changed

+562
-6
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,9 @@ jobs:
7272
working-directory: ${{ env.working_dir }}
7373
- run: pytest
7474
working-directory: ${{ env.working_dir }}
75+
- if: ${{ env[matrix.python-version] == '3.12' && !env[matrix.openai-version] }}
76+
# Only run on latest python and openai client version because we are calling openai
77+
run: pytest --integration-tests
78+
working-directory: ${{ env.working_dir }}
79+
env:
80+
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}

instrumentation/elastic-opentelemetry-instrumentation-openai/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ pip install -r dev-requirements.txt
7171
pytest
7272
```
7373

74+
To run integration tests doing real requests:
75+
76+
```
77+
OPENAI_API_KEY=unused pytest --integration-tests
78+
```
79+
7480
## Refreshing HTTP payloads
7581

7682
We use [VCR.py](https://vcrpy.readthedocs.io/en/latest/) to automatically record HTTP responses from

instrumentation/elastic-opentelemetry-instrumentation-openai/tests/conftest.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,3 +498,26 @@ def assert_token_usage_metric(
498498
),
499499
],
500500
)
501+
502+
503+
def pytest_addoption(parser):
504+
parser.addoption(
505+
"--integration-tests",
506+
action="store_true",
507+
default=False,
508+
help="run integrations tests doing real requests",
509+
)
510+
511+
512+
def pytest_configure(config):
513+
config.addinivalue_line("markers", "integration: mark integration tests")
514+
515+
516+
def pytest_collection_modifyitems(config, items):
517+
run_integration_tests = bool(config.getoption("integration_tests"))
518+
reason = "running integrations tests only" if run_integration_tests else "skipping integration tests"
519+
skip_mark = pytest.mark.skip(reason=reason)
520+
for item in items:
521+
test_is_integration = "integration" in item.keywords
522+
if run_integration_tests != test_is_integration:
523+
item.add_marker(skip_mark)

0 commit comments

Comments
 (0)