From 527d4ce9852ee933487b08f86046e03a5ee95205 Mon Sep 17 00:00:00 2001 From: Michael Thornton Date: Mon, 16 Dec 2024 16:33:09 -0800 Subject: [PATCH] disable autouse on mock_api fixture --- .github/workflows/blt.yml | 2 +- pyproject.toml | 5 +++++ pytest.xml | 10 +++++++++- tests/conftest.py | 2 +- tests/test_nmdcapi.py | 10 +++++----- tests/test_nmdcapi_integration.py | 31 +++++++++++++++++++++++++++++++ tests/test_watch_nmdc.py | 2 +- 7 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 tests/test_nmdcapi_integration.py diff --git a/.github/workflows/blt.yml b/.github/workflows/blt.yml index 366d357f..8e65873c 100644 --- a/.github/workflows/blt.yml +++ b/.github/workflows/blt.yml @@ -45,5 +45,5 @@ jobs: - name: Test with pytest run: | - poetry run pytest ./tests --junit-xml=pytest.xml --cov-report=term \ + poetry run pytest -m "not integration" ./tests --junit-xml=pytest.xml --cov-report=term \ --cov-report=xml --cov=nmdc_automation --local-badge-output-dir badges/ diff --git a/pyproject.toml b/pyproject.toml index 62af6630..6e258163 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,3 +43,8 @@ style = "pep440" [build-system] requires = ["poetry-core"] build-backend = "poetry.core.masonry.api" + +[tool.pytest.ini_options] +markers = [ + "integration: mark test as integration test", +] diff --git a/pytest.xml b/pytest.xml index aa997e1b..e6d13a6b 100644 --- a/pytest.xml +++ b/pytest.xml @@ -1 +1,9 @@ - \ No newline at end of file +requests_mock = <requests_mock.mocker.Mocker object at 0x10c76b650>, site_config_file = PosixPath('/Users/MBThornton/Documents/code/nmdc_automation/tests/site_configuration_test.toml') + + @pytest.mark.integration + def test_nmdcapi_basics(requests_mock, site_config_file): +> assert False, "Unimplemented" +E AssertionError: Unimplemented +E assert False + +tests/test_nmdcapi_integration.py:10: AssertionError \ No newline at end of file diff --git a/tests/conftest.py b/tests/conftest.py index 8a0187c4..223d5378 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -67,7 +67,7 @@ def test_db(): conn_str = os.environ.get("MONGO_URL", "mongodb://localhost:27017") return MongoClient(conn_str).test -@fixture(autouse=True) +@fixture(scope="function") def mock_api(monkeypatch, requests_mock, test_data_dir): monkeypatch.setenv("NMDC_API_URL", "http://localhost") monkeypatch.setenv("NMDC_CLIENT_ID", "anid") diff --git a/tests/test_nmdcapi.py b/tests/test_nmdcapi.py index 060c3200..b06c6dd0 100644 --- a/tests/test_nmdcapi.py +++ b/tests/test_nmdcapi.py @@ -3,7 +3,7 @@ import os -def test_basics(requests_mock, site_config_file): +def test_basics(requests_mock, site_config_file, mock_api): n = nmdcapi(site_config_file) # Add decode description @@ -14,7 +14,7 @@ def test_basics(requests_mock, site_config_file): assert "metadata" in resp -def test_objects(requests_mock, site_config_file, test_data_dir): +def test_objects(requests_mock, site_config_file, test_data_dir, mock_api): n = nmdcapi(site_config_file) requests_mock.post("http://localhost/objects", json={}) @@ -37,7 +37,7 @@ def test_objects(requests_mock, site_config_file, test_data_dir): assert "a" in resp -def test_list_funcs(requests_mock, site_config_file, test_data_dir): +def test_list_funcs(requests_mock, site_config_file, test_data_dir, mock_api): n = nmdcapi(site_config_file) mock_resp = json.load(open(test_data_dir / "mock_jobs.json")) @@ -55,7 +55,7 @@ def test_list_funcs(requests_mock, site_config_file, test_data_dir): assert resp is not None -def test_update_op(requests_mock, site_config_file): +def test_update_op(requests_mock, site_config_file, mock_api): n = nmdcapi(site_config_file) mock_resp = {'metadata': {"b": "c"}} @@ -69,7 +69,7 @@ def test_update_op(requests_mock, site_config_file): assert "b" in resp["metadata"] -def test_jobs(requests_mock, site_config_file): +def test_jobs(requests_mock, site_config_file, mock_api): n = nmdcapi(site_config_file) requests_mock.get("http://localhost/jobs/abc", json="jobs/") diff --git a/tests/test_nmdcapi_integration.py b/tests/test_nmdcapi_integration.py new file mode 100644 index 00000000..d03b2bc5 --- /dev/null +++ b/tests/test_nmdcapi_integration.py @@ -0,0 +1,31 @@ +""" Integration tests for the NMDC API. """ + +import pytest +import requests + +from nmdc_automation.api.nmdcapi import NmdcRuntimeApi as nmdcapi + + + +@pytest.mark.integration +def test_integration_environment(): + """ + Test that the integration environment is set up correctly: + - Runtime API server is running on localhost port 8000 + - MongoDB is running on localhost port 27017 + - The site 'NERSC' exists in the API + + If any of these conditions are not met, the test will fail, and the remaining integration + tests will be skipped. + """ + # response = requests.get("http://localhost:8000") + # assert response.status_code == 200 + assert False, "Unimplemented" + + + + +@pytest.mark.integration +def test_nmdcapi_basics(requests_mock, site_config_file): + assert False, "Unimplemented" + diff --git a/tests/test_watch_nmdc.py b/tests/test_watch_nmdc.py index 34f36261..cbdfc386 100644 --- a/tests/test_watch_nmdc.py +++ b/tests/test_watch_nmdc.py @@ -417,7 +417,7 @@ def test_claim_jobs(mock_submit, site_config_file, site_config, fixtures_dir): assert unclaimed_wfj.job_status -def test_runtime_manager_get_unclaimed_jobs(site_config, initial_state_file_1_failure, fixtures_dir): +def test_runtime_manager_get_unclaimed_jobs(site_config, initial_state_file_1_failure, fixtures_dir, mock_api): # Arrange rt = RuntimeApiHandler(site_config) # Act