I'm developing a smaller Python module, which is on GitHub and connected with Travis-CI and codecov. I'm trying to write unittests for everything. This is a sketch of the file I want to test:
method.py
'''
...
other import statements
'''
try:
from lmfit import Model
_has_lmfit = True
except ImportError:
_has_lmfit = False
def method1(arg1, arg2, etc..):
if _has_lmfit:
#do stuff
else:
#do other stuff
So clearly if lmfit is available the else block is never touched by the unittests. Otherwise the first block is never executed. I tried to solve the problem with the Travis config file: I created two envs and I don't install lmfit at nolmfit
env. It looks something like this.
env:
- version=withlmfit
- version=nolmfit
...
script:
- python test_method.py
- python test_otherfile.py
- coverage run test_loading.py
- coverage run -a test_otherfile.py
after_success:
- codecov
Currently I'm using the default python unittest
module to write tests, and I run them one-by-one, as shown above. I don't know it's the correct way to do this (or should I switch to pytest
).
With the config above both environments run successfully, but the reports are not merged, so codecov still shows that half of the code is tested. I'd really appreciate if anyone could help me to clarify this, because there should be one-- and preferably only one --obvious way to do it.