Merge pull request #32931 from azat/integration-cleanup_environment-fix

tests/integration/cleanup_environment: fix obtaining PYTEST_CLEANUP_CONTAINERS
This commit is contained in:
alexey-milovidov 2021-12-19 07:51:28 +03:00 committed by GitHub
commit a743d79980
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,12 +8,12 @@ from helpers.network import _NetworkManager
@pytest.fixture(autouse=True, scope="session")
def cleanup_environment():
try:
if int(os.environ.get("PYTEST_CLEANUP_CONTAINERS")) == 1:
if int(os.environ.get("PYTEST_CLEANUP_CONTAINERS", 0)) == 1:
logging.debug(f"Cleaning all iptables rules")
_NetworkManager.clean_all_user_iptables_rules()
result = run_and_check(['docker ps | wc -l'], shell=True)
if int(result) > 1:
if int(os.environ.get("PYTEST_CLEANUP_CONTAINERS")) != 1:
if int(os.environ.get("PYTEST_CLEANUP_CONTAINERS", 0)) != 1:
logging.warning(f"Docker containters({int(result)}) are running before tests run. They can be left from previous pytest run and cause test failures.\n"\
"You can set env PYTEST_CLEANUP_CONTAINERS=1 or use runner with --cleanup-containers argument to enable automatic containers cleanup.")
else: