biocommons / hgvs

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

Use pytest fixtures rather than instantiating new objects #507

Open reece opened 6 years ago

reece commented 6 years ago
snafu$ for w in 'connect(' VariantMapper AssemblyMapper Normalizer Validator; do printf "%d $w\n" $(fgrep $w tests/*.py|wc -l); done

18 connect(
16 VariantMapper
15 AssemblyMapper
11 Normalizer
10 Validator

These are the minimum number of times we connect or instantiate these objects for tests. (The above excludes cases where we instantiate in loops, if any.)

Instead, use common fixtures that are created once per test session.

jamesBrosnahan commented 6 years ago

I found this relevant gist post about modularizing pytest fixtures: How to modularize your py.test fixtures there is a post by ikonst recommending to create a local pytest plugin to store fixtures.

tests/test_hgvs_variantmapper.py and tests/test_hgvs_variantmapper_gcp.py have almost identical setUp() functions and could be replaced with pytest fixtures. tests/test_hgvs_variantmapper.py @classmethod def setUpClass(cls): cls.hdp = hgvs.dataproviders.uta.connect(mode=os.environ.get("HGVS_CACHE_MODE", "run"), cache=CACHE) cls.vm = hgvs.variantmapper.VariantMapper(cls.hdp) cls.hp = hgvs.parser.Parser() tests/test_hgvs_variantmapper_gcp.py def setUp(self): self.hdp = hgvs.dataproviders.uta.connect(mode=os.environ.get("HGVS_CACHE_MODE", "run"), cache=CACHE) self.hm = hgvs.variantmapper.VariantMapper(self.hdp) self.hp = hgvs.parser.Parser()