2020-12-28 18:52:29 +01:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
from django_ynh.local_test import create_local_test
|
|
|
|
from django_ynh.path_utils import assert_is_dir, assert_is_file
|
|
|
|
|
|
|
|
|
|
|
|
def run_pytest(django_settings_path, destination):
|
2020-12-28 20:15:21 +01:00
|
|
|
"""
|
|
|
|
1. Generate "local test installation"
|
|
|
|
2. Run pytest against generated sources
|
|
|
|
"""
|
2020-12-28 18:52:29 +01:00
|
|
|
assert_is_file(django_settings_path)
|
|
|
|
|
|
|
|
conf_path = django_settings_path.parent
|
|
|
|
base_path = conf_path.parent
|
|
|
|
test_path = Path(base_path / 'tests')
|
|
|
|
|
|
|
|
assert_is_dir(test_path)
|
|
|
|
|
|
|
|
final_home_path = create_local_test(
|
|
|
|
django_settings_path=django_settings_path,
|
|
|
|
destination=destination,
|
|
|
|
runserver=False,
|
|
|
|
)
|
|
|
|
django_settings_name = django_settings_path.stem
|
|
|
|
os.environ['DJANGO_SETTINGS_MODULE'] = django_settings_name
|
|
|
|
print(f'DJANGO_SETTINGS_MODULE={django_settings_name}')
|
|
|
|
|
|
|
|
sys.path.insert(0, str(final_home_path))
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
2020-12-29 11:42:34 +01:00
|
|
|
# collect only project tests and pass existing pytest arguments:
|
|
|
|
sys.argv = [__file__, str(test_path)] + sys.argv[1:]
|
2020-12-28 18:52:29 +01:00
|
|
|
|
|
|
|
raise SystemExit(pytest.console_main())
|