We need to set RUNTIME_VARS.PYTEST_SESSION sooner

This commit is contained in:
Pedro Algarvio 2020-09-14 18:29:48 +01:00
parent ed383370f2
commit 19c851b2b9
No known key found for this signature in database
GPG key ID: BB36BF6584A298FF
2 changed files with 27 additions and 24 deletions

View file

@ -288,7 +288,7 @@ def _install_requirements(session, transport, *extra_requirements):
session.install(*install_command, silent=PIP_INSTALL_SILENT)
def _run_with_coverage(session, *test_cmd):
def _run_with_coverage(session, *test_cmd, env=None):
if SKIP_REQUIREMENTS_INSTALL is False:
session.install(
"--progress-bar=off", "coverage==5.2", silent=PIP_INSTALL_SILENT
@ -304,19 +304,20 @@ def _run_with_coverage(session, *test_cmd):
python_path_entries.insert(0, SITECUSTOMIZE_DIR)
python_path_env_var = os.pathsep.join(python_path_entries)
env = {
# The updated python path so that sitecustomize is importable
"PYTHONPATH": python_path_env_var,
# The full path to the .coverage data file. Makes sure we always write
# them to the same directory
"COVERAGE_FILE": os.path.abspath(os.path.join(REPO_ROOT, ".coverage")),
# Instruct sub processes to also run under coverage
"COVERAGE_PROCESS_START": os.path.join(REPO_ROOT, ".coveragerc"),
}
if IS_DARWIN:
# Don't nuke our multiprocessing efforts objc!
# https://stackoverflow.com/questions/50168647/multiprocessing-causes-python-to-crash-and-gives-an-error-may-have-been-in-progr
env["OBJC_DISABLE_INITIALIZE_FORK_SAFETY"] = "YES"
if env is None:
env = {}
env.update(
{
# The updated python path so that sitecustomize is importable
"PYTHONPATH": python_path_env_var,
# The full path to the .coverage data file. Makes sure we always write
# them to the same directory
"COVERAGE_FILE": os.path.abspath(os.path.join(REPO_ROOT, ".coverage")),
# Instruct sub processes to also run under coverage
"COVERAGE_PROCESS_START": os.path.join(REPO_ROOT, ".coveragerc"),
}
)
try:
session.run(*test_cmd, env=env)
@ -353,6 +354,11 @@ def _run_with_coverage(session, *test_cmd):
def _runtests(session, coverage, cmd_args):
# Create required artifacts directories
_create_ci_directories()
env = {}
if IS_DARWIN:
# Don't nuke our multiprocessing efforts objc!
# https://stackoverflow.com/questions/50168647/multiprocessing-causes-python-to-crash-and-gives-an-error-may-have-been-in-progr
env["OBJC_DISABLE_INITIALIZE_FORK_SAFETY"] = "YES"
try:
if coverage is True:
_run_with_coverage(
@ -360,15 +366,11 @@ def _runtests(session, coverage, cmd_args):
"coverage",
"run",
os.path.join("tests", "runtests.py"),
*cmd_args
*cmd_args,
env=env
)
else:
cmd_args = ["python", os.path.join("tests", "runtests.py")] + list(cmd_args)
env = None
if IS_DARWIN:
# Don't nuke our multiprocessing efforts objc!
# https://stackoverflow.com/questions/50168647/multiprocessing-causes-python-to-crash-and-gives-an-error-may-have-been-in-progr
env = {"OBJC_DISABLE_INITIALIZE_FORK_SAFETY": "YES"}
session.run(*cmd_args, env=env)
except CommandFailed: # pylint: disable=try-except-raise
# Disabling re-running failed tests for the time being
@ -915,11 +917,11 @@ def _pytest(session, coverage, cmd_args):
"pip", "uninstall", "-y", "pytest-salt", silent=True,
)
env = None
env = {"PYTEST_SESSION": "1"}
if IS_DARWIN:
# Don't nuke our multiprocessing efforts objc!
# https://stackoverflow.com/questions/50168647/multiprocessing-causes-python-to-crash-and-gives-an-error-may-have-been-in-progr
env = {"OBJC_DISABLE_INITIALIZE_FORK_SAFETY": "YES"}
env["OBJC_DISABLE_INITIALIZE_FORK_SAFETY"] = "YES"
if CI_RUN:
# We'll print out the collected tests on CI runs.
@ -940,7 +942,8 @@ def _pytest(session, coverage, cmd_args):
"-m",
"pytest",
"--showlocals",
*cmd_args
*cmd_args,
env=env
)
else:
session.run("python", "-m", "pytest", *cmd_args, env=env)

View file

@ -209,6 +209,6 @@ RUNTIME_VARS = RuntimeVars(
BASE_FILES=paths.BASE_FILES,
PROD_FILES=paths.PROD_FILES,
TESTS_DIR=paths.TESTS_DIR,
PYTEST_SESSION=False,
PYTEST_SESSION="PYTEST_SESSION" in os.environ,
)
# <---- Tests Runtime Variables --------------------------------------------------------------------------------------