Skip to content

Commit

Permalink
Allow run_tests to be run from different directories
Browse files Browse the repository at this point in the history
  • Loading branch information
Erotemic committed Jun 9, 2024
1 parent 071a6e0 commit 3e9903d
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions run_tests.py
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())

0 comments on commit 3e9903d

Please sign in to comment.