From c88bbd361c08091197f19dc973bb90e38b07c461 Mon Sep 17 00:00:00 2001 From: Carly Gundy Date: Mon, 16 Dec 2024 13:16:10 +0100 Subject: [PATCH] wip --- .github/workflows/python_lint_test.yml | 4 +++- .gitignore | 1 + reusable_workflows/tests/conftest.py | 14 +++++++------- .../tests/test_check_external_contrib.py | 7 +++++++ reusable_workflows/tests/test_utils.py | 4 ++-- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/.github/workflows/python_lint_test.yml b/.github/workflows/python_lint_test.yml index f320e2a..773c864 100644 --- a/.github/workflows/python_lint_test.yml +++ b/.github/workflows/python_lint_test.yml @@ -33,4 +33,6 @@ jobs: flake8 reusable_workflows/ - name: Run all tests - run: pytest --runslow reusable_workflows/ + run: pytest --integration-tests reusable_workflows/ + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 700939f..93b46df 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ sorting/target **/__pycache__ .env/** +.venv/** diff --git a/reusable_workflows/tests/conftest.py b/reusable_workflows/tests/conftest.py index e446d0a..8e719e8 100644 --- a/reusable_workflows/tests/conftest.py +++ b/reusable_workflows/tests/conftest.py @@ -3,19 +3,19 @@ def pytest_addoption(parser): parser.addoption( - "--runslow", action="store_true", default=False, help="run slow tests" + "--integration-tests", action="store_true", default=False, help="run integration tests" ) def pytest_configure(config): - config.addinivalue_line("markers", "slow: mark test as slow to run") + config.addinivalue_line("markers", "integration: mark test as integration test") def pytest_collection_modifyitems(config, items): - if config.getoption("--runslow"): - # --runslow given in cli: do not skip slow tests + if config.getoption("--integration-tests"): + # --integration-tests given in cli: do not skip integration tests return - skip_slow = pytest.mark.skip(reason="need --runslow option to run") + skip_integration = pytest.mark.skip(reason="need --integration-tests option to run") for item in items: - if "slow" in item.keywords: - item.add_marker(skip_slow) + if "integration" in item.keywords: + item.add_marker(skip_integration) diff --git a/reusable_workflows/tests/test_check_external_contrib.py b/reusable_workflows/tests/test_check_external_contrib.py index 4d44ce8..296720f 100644 --- a/reusable_workflows/tests/test_check_external_contrib.py +++ b/reusable_workflows/tests/test_check_external_contrib.py @@ -1,6 +1,7 @@ import os from unittest import mock +import github3 import pytest from check_membership.check_external_contrib import ( @@ -53,3 +54,9 @@ def test_github_token_not_passed_in(github_login_mock): assert ( str(exc.value) == "github login failed - maybe GH_TOKEN was not correctly set" ) + +@pytest.mark.integration +def test_check_repos_open_to_contributions_accessible(): + gh = github3.login(token=os.getenv("GH_TOKEN")) + + get_repos_open_to_contributions(gh) diff --git a/reusable_workflows/tests/test_utils.py b/reusable_workflows/tests/test_utils.py index 3ae2aaf..f11283f 100644 --- a/reusable_workflows/tests/test_utils.py +++ b/reusable_workflows/tests/test_utils.py @@ -19,7 +19,7 @@ def test_download_file_succeeds_first_try(): assert repo.file_contents.call_count == 1 -@pytest.mark.slow +@pytest.mark.integration def test_download_file_succeeds_third_try(): repo = mock.MagicMock() file_content_obj = mock.Mock() @@ -35,7 +35,7 @@ def test_download_file_succeeds_third_try(): assert repo.file_contents.call_count == 3 -@pytest.mark.slow +@pytest.mark.integration @mock.patch("requests.get") def test_download_file_fails(mock_get): repo = mock.MagicMock()