-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow run_tests to be run from different directories
- Loading branch information
Showing
1 changed file
with
36 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,47 @@ | ||
#!/usr/bin/env python | ||
if __name__ == '__main__': | ||
import sys | ||
|
||
|
||
def get_this_script_fpath(): | ||
import pathlib | ||
try: | ||
fpath = pathlib.Path(__file__) | ||
except NameError: | ||
# This is not being run from a script, thus the developer is doing some | ||
# IPython hacking, so we will assume a path on the developer machine. | ||
fpath = pathlib.Path('~/code/ubelt/run_tests.py').expanduser() | ||
if not fpath.exists(): | ||
raise Exception( | ||
'Unable to determine the file path that this script ' | ||
'should correspond to') | ||
return fpath | ||
|
||
|
||
def main(): | ||
import pytest | ||
import sys | ||
import os | ||
|
||
repo_dpath = get_this_script_fpath().parent | ||
|
||
package_name = 'ubelt' | ||
mod_dpath = 'ubelt' | ||
test_dpath = 'tests' | ||
mod_dpath = repo_dpath / 'ubelt' | ||
test_dpath = repo_dpath / 'tests' | ||
config_fpath = repo_dpath / 'pyproject.toml' | ||
|
||
pytest_args = [ | ||
'--cov-config', 'pyproject.toml', | ||
'--cov-config', os.fspath(config_fpath), | ||
'--cov-report', 'html', | ||
'--cov-report', 'term', | ||
'--durations', '100', | ||
'--xdoctest', | ||
'--cov=' + package_name, | ||
mod_dpath, test_dpath | ||
os.fspath(mod_dpath), | ||
os.fspath(test_dpath) | ||
] | ||
pytest_args = pytest_args + sys.argv[1:] | ||
sys.exit(pytest.main(pytest_args)) | ||
ret = pytest.main(pytest_args) | ||
return ret | ||
|
||
|
||
if __name__ == '__main__': | ||
sys.exit(main()) |