Last active
November 10, 2016 16:48
-
-
Save amarao/5340a5522e7350032b7fda1066912732 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# See description here https://medium.com/@george.shuklin/skeleton-for-pytest-test-8caa0828f53d#.7i9r1q15s | |
# CC-BY-SA | |
import os | |
import inspect | |
import sys | |
import pytest | |
# trick to use tests directory and be able to import from '..' | |
ourfilename = os.path.abspath(inspect.getfile(inspect.currentframe())) | |
currentdir = os.path.dirname(ourfilename) | |
parentdir = os.path.dirname(currentdir) | |
sys.path.insert(0, parentdir) | |
if __name__ == "__main__": | |
file_to_test = os.path.join( | |
parentdir, | |
os.path.basename(parentdir), | |
os.path.basename(ourfilename).replace("test_", '') | |
) | |
pytest.main([ | |
"-vv", | |
"--cov", file_to_test, | |
"--cov-report", "term-missing" | |
] + sys.argv) | |
@pytest.fixture | |
def module(): | |
from myapp import module | |
return module | |
def test_myfunc_simple(module): | |
assert module.myfunc() == True | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment