[unittest] supported condititonal testing based on env var (#1701)

polish code
This commit is contained in:
Frank Lee
2022-10-13 19:38:45 +08:00
committed by GitHub
parent 8283e95db3
commit 0e52f3d3d5
10 changed files with 36 additions and 10 deletions

View File

@@ -0,0 +1,17 @@
import pytest
import os
def run_on_environment_flag(name: str):
"""
Conditionally run a test based on the environment variable. If this environment variable is set
to 1, this test will be executed. Otherwise, this test is skipped. The environment variable is default to 0.
"""
assert isinstance(name, str)
flag = os.environ.get(name.upper(), '0')
reason = f'Environment varialbe {name} is {flag}'
if flag == '1':
return pytest.mark.skipif(False, reason=reason)
else:
return pytest.mark.skipif(True, reason=reason)