Skip to content

Commit

Permalink
disable autouse on mock_api fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
mbthornton-lbl committed Dec 17, 2024
1 parent 4ac3ae4 commit 527d4ce
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/blt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
10 changes: 9 additions & 1 deletion pytest.xml
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
<?xml version="1.0" encoding="utf-8"?><testsuites><testsuite name="pytest" errors="0" failures="0" skipped="0" tests="95" time="15.756" timestamp="2024-11-26T12:32:34.300291" hostname="MBThornton-M92.local"><testcase classname="tests.test_config" name="test_config" time="0.046" /><testcase classname="tests.test_config" name="test_config_missing" time="0.001" /><testcase classname="tests.test_imports" name="test_gold_mapper_map_sequencing_data" time="0.061" /><testcase classname="tests.test_imports" name="test_gold_mapper_map_data_unique" time="0.061" /><testcase classname="tests.test_imports" name="test_gold_mapper_map_data_multiple" time="0.059" /><testcase classname="tests.test_imports" name="test_gold_mapper_map_workflow_executions" time="5.532" /><testcase classname="tests.test_models" name="test_workflow_process_factory" time="0.005" /><testcase classname="tests.test_models" name="test_workflow_process_factory_incorrect_id" time="1.213" /><testcase classname="tests.test_models" name="test_workflow_process_factory_data_generation_invalid_analyte_category" time="0.001" /><testcase classname="tests.test_models" name="test_workflow_process_factory_metagenome_assembly_with_invalid_execution_resource" time="0.001" /><testcase classname="tests.test_models" name="test_workflow_process_factory_mags_with_mags_list" time="0.001" /><testcase classname="tests.test_models" name="test_process_factory_with_db_record" time="0.001" /><testcase classname="tests.test_models" name="test_workflow_process_node[mags_analysis_record.json-nmdc:MagsAnalysis]" time="0.008" /><testcase classname="tests.test_models" name="test_workflow_process_node[metagenome_annotation_record.json-nmdc:MetagenomeAnnotation]" time="0.007" /><testcase classname="tests.test_models" name="test_workflow_process_node[metagenome_assembly_record.json-nmdc:MetagenomeAssembly]" time="0.007" /><testcase classname="tests.test_models" name="test_workflow_process_node[metatranscriptome_annotation_record.json-nmdc:MetatranscriptomeAnnotation]" time="0.007" /><testcase classname="tests.test_models" name="test_workflow_process_node[metatranscriptome_assembly_record.json-nmdc:MetatranscriptomeAssembly]" time="0.007" /><testcase classname="tests.test_models" name="test_workflow_process_node[metatranscriptome_expression_analysis_record.json-nmdc:MetatranscriptomeExpressionAnalysis]" time="0.007" /><testcase classname="tests.test_models" name="test_workflow_process_node[nucleotide_sequencing_record.json-nmdc:NucleotideSequencing]" time="0.071" /><testcase classname="tests.test_models" name="test_workflow_process_node[read_based_taxonomy_analysis_record.json-nmdc:ReadBasedTaxonomyAnalysis]" time="0.007" /><testcase classname="tests.test_models" name="test_workflow_process_node[read_qc_analysis_record.json-nmdc:ReadQcAnalysis]" time="0.007" /><testcase classname="tests.test_models" name="test_data_object_creation_from_records" time="0.145" /><testcase classname="tests.test_models" name="test_data_object_creation_from_db_records" time="0.165" /><testcase classname="tests.test_models" name="test_data_object_creation_invalid_data_object_type" time="0.001" /><testcase classname="tests.test_models" name="test_data_object_creation_invalid_data_category" time="0.001" /><testcase classname="tests.test_models" name="test_job_output_creation" time="0.001" /><testcase classname="tests.test_models" name="test_job_creation" time="0.001" /><testcase classname="tests.test_nmdcapi" name="test_basics" time="0.013" /><testcase classname="tests.test_nmdcapi" name="test_objects" time="0.012" /><testcase classname="tests.test_nmdcapi" name="test_list_funcs" time="0.006" /><testcase classname="tests.test_nmdcapi" name="test_update_op" time="0.004" /><testcase classname="tests.test_nmdcapi" name="test_jobs" time="0.006" /><testcase classname="tests.test_sched" name="test_scheduler_cycle[workflows.yaml]" time="0.042" /><testcase classname="tests.test_sched" name="test_scheduler_cycle[workflows-mt.yaml]" time="0.047" /><testcase classname="tests.test_sched" name="test_progress[workflows.yaml]" time="0.321" /><testcase classname="tests.test_sched" name="test_progress[workflows-mt.yaml]" time="0.193" /><testcase classname="tests.test_sched" name="test_multiple_versions" time="0.183" /><testcase classname="tests.test_sched" name="test_out_of_range" time="0.083" /><testcase classname="tests.test_sched" name="test_type_resolving" time="0.107" /><testcase classname="tests.test_sched" name="test_scheduler_add_job_rec[workflows.yaml]" time="0.011" /><testcase classname="tests.test_sched" name="test_scheduler_add_job_rec[workflows-mt.yaml]" time="0.009" /><testcase classname="tests.test_sched" name="test_scheduler_find_new_jobs" time="0.073" /><testcase classname="tests.test_watch_nmdc" name="test_file_handler_init_from_state_file" time="0.006" /><testcase classname="tests.test_watch_nmdc" name="test_file_handler_init_from_config_agent_state" time="0.002" /><testcase classname="tests.test_watch_nmdc" name="test_file_handler_init_default_state" time="0.002" /><testcase classname="tests.test_watch_nmdc" name="test_file_handler_read_state" time="0.001" /><testcase classname="tests.test_watch_nmdc" name="test_file_handler_write_state" time="0.005" /><testcase classname="tests.test_watch_nmdc" name="test_file_handler_get_output_path" time="0.001" /><testcase classname="tests.test_watch_nmdc" name="test_file_handler_write_metadata_if_not_exists" time="0.002" /><testcase classname="tests.test_watch_nmdc" name="test_job_manager_init" time="0.001" /><testcase classname="tests.test_watch_nmdc" name="test_job_manager_restore_from_state" time="0.001" /><testcase classname="tests.test_watch_nmdc" name="test_job_manager_job_checkpoint" time="0.001" /><testcase classname="tests.test_watch_nmdc" name="test_job_manager_save_checkpoint" time="0.002" /><testcase classname="tests.test_watch_nmdc" name="test_job_manager_find_job_by_opid" time="0.002" /><testcase classname="tests.test_watch_nmdc" name="test_job_manager_prepare_and_cache_new_job" time="0.001" /><testcase classname="tests.test_watch_nmdc" name="test_job_manager_prepare_and_cache_new_job_force" time="0.002" /><testcase classname="tests.test_watch_nmdc" name="test_job_manager_get_finished_jobs" time="0.002" /><testcase classname="tests.test_watch_nmdc" name="test_job_manager_process_successful_job" time="0.327" /><testcase classname="tests.test_watch_nmdc" name="test_job_manager_get_finished_jobs_1_failure" time="0.003" /><testcase classname="tests.test_watch_nmdc" name="test_job_manager_process_failed_job_1_failure" time="0.004" /><testcase classname="tests.test_watch_nmdc" name="test_job_manager_process_failed_job_2_failures" time="0.003" /><testcase classname="tests.test_watch_nmdc" name="test_claim_jobs" time="2.004" /><testcase classname="tests.test_watch_nmdc" name="test_runtime_manager_get_unclaimed_jobs" time="0.047" /><testcase classname="tests.test_watch_nmdc" name="test_reclaim_job" time="0.001" /><testcase classname="tests.test_watch_nmdc" name="test_watcher_restore_from_checkpoint" time="0.001" /><testcase classname="tests.test_wfutils" name="test_workflow_job" time="0.001" /><testcase classname="tests.test_wfutils" name="test_cromwell_job_runner" time="0.001" /><testcase classname="tests.test_wfutils" name="test_cromwell_job_runner_get_job_status" time="0.003" /><testcase classname="tests.test_wfutils" name="test_cromwell_job_runner_get_job_metadata" time="0.002" /><testcase classname="tests.test_wfutils" name="test_workflow_job_as_workflow_execution_dict" time="0.001" /><testcase classname="tests.test_wfutils" name="test_workflow_state_manager" time="0.001" /><testcase classname="tests.test_wfutils" name="test_workflow_manager_fetch_release_file_success" time="0.002" /><testcase classname="tests.test_wfutils" name="test_workflow_manager_fetch_release_file_failed_download" time="0.001" /><testcase classname="tests.test_wfutils" name="test_workflow_manager_fetch_release_file_failed_write" time="0.002" /><testcase classname="tests.test_wfutils" name="test_cromwell_runner_setup_inputs_and_labels" time="0.001" /><testcase classname="tests.test_wfutils" name="test_cromwell_runner_generate_submission_files" time="0.003" /><testcase classname="tests.test_wfutils" name="test_cromwell_runner_generate_submission_files_exception" time="0.003" /><testcase classname="tests.test_wfutils" name="test_cromwell_job_runner_submit_job_new_job" time="0.002" /><testcase classname="tests.test_wfutils" name="test_workflow_job_data_objects_and_execution_record_mags" time="0.004" /><testcase classname="tests.test_wfutils" name="test_workflow_job_from_database_job_record" time="0.001" /><testcase classname="tests.test_workflow_process" name="test_load_workflow_process_nodes[workflows.yaml]" time="0.025" /><testcase classname="tests.test_workflow_process" name="test_load_workflow_process_nodes[workflows-mt.yaml]" time="0.026" /><testcase classname="tests.test_workflow_process" name="test_load_workflow_process_nodes_with_obsolete_versions" time="0.017" /><testcase classname="tests.test_workflow_process" name="test_resolve_relationships" time="0.019" /><testcase classname="tests.test_workflow_process" name="test_load_workflow_process_nodes_does_not_load_metagenome_sequencing" time="0.014" /><testcase classname="tests.test_workflow_process" name="test_load_workflows[workflows.yaml]" time="0.004" /><testcase classname="tests.test_workflow_process" name="test_load_workflows[workflows-mt.yaml]" time="0.003" /><testcase classname="tests.test_workflow_process" name="test_get_required_data_objects_by_id[workflows.yaml]" time="0.012" /><testcase classname="tests.test_workflow_process" name="test_get_required_data_objects_by_id[workflows-mt.yaml]" time="0.013" /><testcase classname="tests.test_workflow_process" name="test_within_range" time="0.001" /><testcase classname="tests.test_jgi_file_staging.test_file_metadata" name="test_get_access_token" time="0.001" /><testcase classname="tests.test_jgi_file_staging.test_file_metadata" name="test_check_access_token" time="1.009" /><testcase classname="tests.test_jgi_file_staging.test_file_metadata" name="test_check_access_token_invalid" time="1.009" /><testcase classname="tests.test_jgi_file_staging.test_file_metadata" name="test_get_sequence_id" time="2.017" /><testcase classname="tests.test_jgi_file_staging.test_file_metadata" name="test_get_analysis_projects_from_proposal_id" time="0.034" /></testsuite></testsuites>
<?xml version="1.0" encoding="utf-8"?><testsuites><testsuite name="pytest" errors="0" failures="1" skipped="0" tests="1" time="0.404" timestamp="2024-12-16T16:04:17.583510" hostname="MBThornton-M92.local"><testcase classname="tests.test_nmdcapi_integration" name="test_nmdcapi_basics" time="0.002"><failure message="AssertionError: Unimplemented&#10;assert False">requests_mock = &lt;requests_mock.mocker.Mocker object at 0x10c76b650&gt;, 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):
&gt; assert False, "Unimplemented"
E AssertionError: Unimplemented
E assert False

tests/test_nmdcapi_integration.py:10: AssertionError</failure></testcase></testsuite></testsuites>
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
10 changes: 5 additions & 5 deletions tests/test_nmdcapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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={})
Expand All @@ -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"))

Expand All @@ -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"}}
Expand All @@ -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/")
Expand Down
31 changes: 31 additions & 0 deletions tests/test_nmdcapi_integration.py
Original file line number Diff line number Diff line change
@@ -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"

2 changes: 1 addition & 1 deletion tests/test_watch_nmdc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 527d4ce

Please sign in to comment.