biocommons / hgvs

Python library to parse, format, validate, normalize, and map sequence variants. `pip install hgvs`
https://hgvs.readthedocs.io/
Apache License 2.0
240 stars 94 forks source link

Remove test HTTP network calls #697

Closed ecalifornica closed 1 year ago

ecalifornica commented 1 year ago

The tests make network calls to https://eutils.ncbi.nlm.nih.gov, causing the tests to be slow and flaky.

This PR updates the pytest vcrpy plugin from pytest-vcr to the actively maintained pytest-recording, which also allows for blocking network access to confirm that all network calls are mocked.

Slowest ten tests without network mocking:

============================================ slowest 10 durations ============================================
22.42s call     tests/test_hgvs_extras_babelfish.py::test_hgvs_to_vcf                                        
20.49s call     tests/issues/test_437.py::Test437_RMRP::test_terminii                                        
18.54s call     tests/issues/test_437.py::test_invitae_examples                                              
11.25s call     tests/issues/test_437.py::test_oob_dup                                                        
6.01s call     tests/issues/test_477.py::test_pair[GPHB5/GRCh37/rs1221379530]                                
5.97s call     tests/issues/test_602.py::test_602                                                             
5.87s call     tests/issues/test_477.py::test_pair[COX6A2/GRCh38/rs755670336]                                
5.81s call     tests/test_hgvs_variantmapper.py::test_add_gene_symbol                                        
5.76s call     tests/issues/test_477.py::test_pair[GPHB5/GRCh37/rs1380832691]                                
5.74s call     tests/issues/test_477.py::test_pair[COX6A2/GRCh38/rs764753905]    

Slowest ten tests with network mocking:

============================================ slowest 10 durations ============================================
1.86s call     tests/issues/test_04xx.py::Test_Issues::test_459_exception_when_ac_nonexistent
1.39s setup    tests/test_hgvs_dataproviders_uta.py::Test_hgvs_dataproviders_uta_with_pooling_without_cache::t
est_get_acs_for_protein_seq 
1.36s setup    tests/test_hgvs_variantmapper_cp_real.py::TestHgvsCToPReal::test_c_to_p_ext
1.34s setup    tests/test_hgvs_dataproviders_uta.py::TestUTAPool::test_get_acs_for_protein_seq
0.60s call     tests/test_hgvs_variantmapper_gcp.py::Test_VariantMapper::test_DNAH11_dbSNP_NM_001277115
0.49s call     tests/test_hgvs_variantmapper_gcp.py::Test_VariantMapper::test_DNAH11_dbSNP_NM_003777
0.39s call     tests/test_hgvs_variantmapper_gcp.py::Test_VariantMapper::test_JRK_dbSNP
0.39s call     tests/test_hgvs_variantmapper_gcp.py::Test_VariantMapper::test_ORAI1_dbSNP
0.38s call     tests/test_hgvs_variantmapper_gcp.py::Test_VariantMapper::test_real
0.29s call     tests/test_hgvs_variantmapper_gcp.py::Test_VariantMapper::test_FOLR3_dbSNP

See also: https://til.simonwillison.net/pytest/pytest-recording-vcr