Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Erotemic committed Apr 27, 2024
1 parent 681ece5 commit aa88190
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions run_tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#!/usr/bin/env python
"""
Based on template in rc/run_tests.binpy.py.in
"""
import os
import sqlite3
import sys
Expand Down Expand Up @@ -77,10 +80,10 @@ def copy_coverage_cibuildwheel_docker(runner_project_dir):
def main():
import pytest
import pathlib
cwd = os.getcwd()
orig_cwd = os.getcwd()
repo_dir = pathlib.Path(__file__).parent.absolute()
test_dir = repo_dir / 'tests'
print('[run_tests] cwd = {!r}'.format(cwd))
print('[run_tests] cwd = {!r}'.format(orig_cwd))

# Prefer testing the installed version, but fallback to testing the
# development version.
Expand All @@ -95,21 +98,24 @@ def main():
# ubelt to check to see if ``package_name`` can be resolved to a path.
temp_path = [pathlib.Path(p).resolve() for p in sys.path]
_resolved_repo_dir = repo_dir.resolve()
print(f'[run_tests] Searching for installed version of {package_name}.')
if _resolved_repo_dir in temp_path:
print(f'[run_tests] Removing _resolved_repo_dir={_resolved_repo_dir} from search path')
temp_path.remove(_resolved_repo_dir)
print(f'[run_tests] Searching for installed version of {package_name}.')
modpath = ub.modname_to_modpath(package_name, sys_path=temp_path)
_temp_path = [os.fspath(p) for p in temp_path]
modpath = ub.modname_to_modpath(package_name, sys_path=_temp_path)
if modpath is not None:
# If it does, then import it. This should cause the installed version
# to be used on further imports even if the repo_dir is in the path.
print(f'[run_tests] Using installed version of {package_name}')
print(f'[run_tests] Found installed version of {package_name}')
print(f'[run_tests] modpath={modpath}')
modpath_contents = list(pathlib.Path(modpath).glob('*'))
print(f'[run_tests] modpath_contents = {ub.urepr(modpath_contents, nl=1)}')
# module = ub.import_module_from_path(modpath, index=0)
# print(f'[run_tests] Installed module = {module!r}')
else:
print(f'[run_tests] No installed version of {package_name} found')
print(f'[run_tests] Searched Paths: {ub.urepr(temp_path, nl=1)}')

try:
print('[run_tests] Changing dirs to test_dir={!r}'.format(test_dir))
Expand Down Expand Up @@ -140,11 +146,11 @@ def main():
print(f'[run_tests] pytest exception: {ex}')
retcode = 1
finally:
os.chdir(cwd)
os.chdir(orig_cwd)
if is_cibuildwheel():
# for CIBW under linux
copy_coverage_cibuildwheel_docker(f'/home/runner/work/{package_name}/{package_name}')
print('[run_tests] Restoring cwd = {!r}'.format(cwd))
print('[run_tests] Restoring cwd = {!r}'.format(orig_cwd))
return retcode


Expand Down

0 comments on commit aa88190

Please sign in to comment.