Skip to content

Commit

Permalink
better idea: monkeypatch the env var
Browse files Browse the repository at this point in the history
  • Loading branch information
anakin87 committed Mar 6, 2024
1 parent 5079df0 commit bab0e2e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
8 changes: 2 additions & 6 deletions test/core/pipeline/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#
# SPDX-License-Identifier: Apache-2.0
import logging
import os
from typing import List, Optional
from unittest.mock import patch

Expand Down Expand Up @@ -701,11 +700,8 @@ def test_describe_no_outputs():
assert p.outputs() == {}


@pytest.mark.skipif(
not os.environ.get("OPENAI_API_KEY", None),
reason="Export an env var called OPENAI_API_KEY containing the OpenAI API key to run this test.",
)
def test_from_template():
def test_from_template(monkeypatch):
monkeypatch.setenv("OPENAI_API_KEY", "fake_key")
pipe = Pipeline.from_template(PredefinedPipeline.INDEXING)
assert pipe.get_component("cleaner")

Expand Down
8 changes: 2 additions & 6 deletions test/core/pipeline/test_templates.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import tempfile

import pytest
Expand Down Expand Up @@ -44,12 +43,9 @@ def test_from_predefined(self):
tpl = PipelineTemplate.from_predefined(PredefinedPipeline.INDEXING)
assert len(tpl.template_content)

@pytest.mark.skipif(
not os.environ.get("OPENAI_API_KEY", None),
reason="Export an env var called OPENAI_API_KEY containing the OpenAI API key to run this test.",
)
# Building a pipeline directly using all default components specified in a predefined or custom template.
def test_build_pipeline_with_default_components(self):
def test_build_pipeline_with_default_components(self, monkeypatch):
monkeypatch.setenv("OPENAI_API_KEY", "fake_key")
rendered = PipelineTemplate.from_predefined(PredefinedPipeline.INDEXING).render()
pipeline = Pipeline.loads(rendered)

Expand Down

0 comments on commit bab0e2e

Please sign in to comment.