From 25c10af7502de980642d4ac5c6f431f40c70d889 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Sun, 28 Jun 2020 20:45:07 +0800 Subject: [PATCH] fix: compatibility for `black` on Android termux system that does not support multiprocessing --- docs/CHANGELOG.md | 3 ++- httprunner/make.py | 10 ++++++++-- httprunner/utils.py | 13 ++++++++++++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 2870880e..669ae263 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,10 +1,11 @@ # Release History -## 3.1.2 (2020-06-23) +## 3.1.2 (2020-06-28) **Fixed** - fix: missing setup/teardown hooks for referenced testcase +- fix: compatibility for `black` on Android termux that does not support multiprocessing well ## 3.1.1 (2020-06-23) diff --git a/httprunner/make.py b/httprunner/make.py index 4cb86e87..c0bf71c2 100644 --- a/httprunner/make.py +++ b/httprunner/make.py @@ -24,7 +24,7 @@ from httprunner.loader import ( convert_relative_project_root_dir, ) from httprunner.response import uniform_validator -from httprunner.utils import override_config_variables +from httprunner.utils import override_config_variables, is_support_multiprocessing """ cache converted pytest files, avoid duplicate making """ @@ -160,7 +160,13 @@ def convert_testcase_path(testcase_abs_path: Text) -> Tuple[Text, Text]: def format_pytest_with_black(*python_paths: Text) -> NoReturn: logger.info("format pytest cases with black ...") try: - subprocess.run(["black", *python_paths]) + if is_support_multiprocessing() or len(python_paths) <= 1: + subprocess.run(["black", *python_paths]) + else: + logger.warning( + f"this system does not support multiprocessing well, format files one by one ..." + ) + [subprocess.run(["black", path]) for path in python_paths] except subprocess.CalledProcessError as ex: capture_exception(ex) logger.error(ex) diff --git a/httprunner/utils.py b/httprunner/utils.py index d832f881..c0e27ed9 100644 --- a/httprunner/utils.py +++ b/httprunner/utils.py @@ -4,13 +4,15 @@ import json import os.path import platform import uuid +from multiprocessing import Queue from typing import Dict, List, Any import sentry_sdk +from loguru import logger + from httprunner import __version__ from httprunner import exceptions from httprunner.models import VariablesMapping -from loguru import logger def init_sentry_sdk(): @@ -209,3 +211,12 @@ def override_config_variables( variables = copy.deepcopy(config_variables) variables.update(step_new_variables) return variables + + +def is_support_multiprocessing() -> bool: + try: + Queue() + return True + except (ImportError, OSError): + # system that does not support semaphores(dependency of multiprocessing), like Android termux + return False