From c9250d4fca86c6b443300b5f4875ec35dfe9560f Mon Sep 17 00:00:00 2001 From: Liqun Li Date: Tue, 19 Dec 2023 17:19:18 +0800 Subject: [PATCH] A pytest flow. (#80) A pytest flow. --------- Co-authored-by: Jack Q --- .github/workflows/pytest.yml | 43 ++++++++++++++++++++++++ requirements.txt | 3 +- tests/unit_tests/test_embedding.py | 11 ++++-- tests/unit_tests/test_plugin_selector.py | 4 +++ 4 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/pytest.yml diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml new file mode 100644 index 00000000..2846e23a --- /dev/null +++ b/.github/workflows/pytest.yml @@ -0,0 +1,43 @@ +name: Python package + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + pytest: + + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.11"] + + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Display Python version + run: python -c "import sys; print(sys.version)" + - name: Install taskweaver + run: | + python -m pip install --upgrade pip setuptools wheel + pip install -e . + - name: Test with pytest + run: | + pip install pytest pytest-cov + pytest tests/unit_tests --collect-only + pytest tests/unit_tests -v --junitxml=junit/test-results-${{ matrix.python-version }}.xml --cov=com --cov-report=xml --cov-report=html + - name: Upload pytest test results + uses: actions/upload-artifact@v3 + with: + name: pytest-results-${{ matrix.python-version }} + path: junit/test-results-${{ matrix.python-version }}.xml + # Use always() to always run this step to publish test results when there are test failures + if: ${{ always() }} + diff --git a/requirements.txt b/requirements.txt index f419c961..cc07fac1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,9 +8,10 @@ pyyaml>=6.0 scikit-learn>=1.2.2 click>=8.0.1 urllib3>=1.26.17 -jsonschema==4.17.3 +jsonschema==4.20.0 injector>=0.21.0 ijson>=3.2.3 +requests>=2.31.0 # Code Execution related ipykernel==6.26.0 diff --git a/tests/unit_tests/test_embedding.py b/tests/unit_tests/test_embedding.py index dbdd6e73..a96af2c1 100644 --- a/tests/unit_tests/test_embedding.py +++ b/tests/unit_tests/test_embedding.py @@ -1,3 +1,5 @@ +import os + import pytest from injector import Injector @@ -7,7 +9,10 @@ from taskweaver.llm.openai import OpenAIService from taskweaver.llm.sentence_transformer import SentenceTransformerService +IN_GITHUB_ACTIONS = os.getenv("GITHUB_ACTIONS") == "true" + +@pytest.mark.skipif(IN_GITHUB_ACTIONS, reason="Test doesn't work in Github Actions.") def test_sentence_transformer_embedding(): app_injector = Injector([]) app_config = AppConfigSource( @@ -29,7 +34,7 @@ def test_sentence_transformer_embedding(): assert len(embedding1[1]) == 768 -@pytest.mark.skip(reason="missing api key") +@pytest.mark.skipif(IN_GITHUB_ACTIONS, reason="Test doesn't work in Github Actions.") def test_openai_embedding(): app_injector = Injector() app_config = AppConfigSource( @@ -51,7 +56,7 @@ def test_openai_embedding(): assert len(embedding1[1]) == 1536 -@pytest.mark.skip(reason="missing api key") +@pytest.mark.skipif(IN_GITHUB_ACTIONS, reason="Test doesn't work in Github Actions.") def test_ollama_embedding(): app_injector = Injector() app_config = AppConfigSource( @@ -71,7 +76,7 @@ def test_ollama_embedding(): assert len(embedding1[1]) == 4096 -@pytest.mark.skip(reason="missing api key") +@pytest.mark.skipif(IN_GITHUB_ACTIONS, reason="Test doesn't work in Github Actions.") def test_qwen_embedding(): app_injector = Injector() app_config = AppConfigSource( diff --git a/tests/unit_tests/test_plugin_selector.py b/tests/unit_tests/test_plugin_selector.py index d0cc7250..fd41a758 100644 --- a/tests/unit_tests/test_plugin_selector.py +++ b/tests/unit_tests/test_plugin_selector.py @@ -1,12 +1,16 @@ import os +import pytest from injector import Injector from taskweaver.code_interpreter.code_generator.plugin_selection import PluginSelector from taskweaver.config.config_mgt import AppConfigSource from taskweaver.memory.plugin import PluginModule +IN_GITHUB_ACTIONS = os.getenv("GITHUB_ACTIONS") == "true" + +@pytest.mark.skipif(IN_GITHUB_ACTIONS, reason="Test doesn't work in Github Actions.") def test_plugin_selector(): app_injector = Injector([PluginModule]) app_config = AppConfigSource(