接上节:测试平台开发之测试框架改造并发执行及结果隔离(1)
上节博客的末尾提到:在命令窗口执行python main.py
可是执行的时候遇到了如下报错:
============================================================================ ERRORS ============================================================================
_____________________________________________________________ ERROR collecting tests/test_case.py ______________________________________________________________
ImportError while importing test module 'D:\cekai\xuexi\Tesla\fullstack_framework\tests\test_case.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
..\.venv\Lib\site-packages\_pytest\python.py:487: in importtestmodulemod = import_path(
..\.venv\Lib\site-packages\_pytest\pathlib.py:591: in import_pathimportlib.import_module(module_name)
D:\python\Lib\importlib\__init__.py:90: in import_modulereturn _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1387: in _gcd_import???
<frozen importlib._bootstrap>:1360: in _find_and_load???
<frozen importlib._bootstrap>:1331: in _find_and_load_unlocked???
<frozen importlib._bootstrap>:935: in _load_unlocked???
..\.venv\Lib\site-packages\_pytest\assertion\rewrite.py:178: in exec_moduleexec(co, module.__dict__)
tests\test_case.py:10: in <module>from commons.case_util import load_case, run_case
commons\case_util.py:12: in <module>from commons import settings
commons\settings.py:7: in <module>from selenium.webdriver.common.by import By
E ModuleNotFoundError: No module named 'selenium'
======================================================================= warnings summary =======================================================================
..\.venv\Lib\site-packages\_pytest\config\__init__.py:1448D:\cekai\xuexi\Tesla\.venv\Lib\site-packages\_pytest\config\__init__.py:1448: PytestConfigWarning: Unknown config option: result_log_verboseself._warn_or_fail_if_strict(f"Unknown config option: {key}\n")..\.venv\Lib\site-packages\_pytest\config\__init__.py:1448D:\cekai\xuexi\Tesla\.venv\Lib\site-packages\_pytest\config\__init__.py:1448: PytestConfigWarning: Unknown config option: xlsx_meta_column_nameself._warn_or_fail_if_strict(f"Unknown config option: {key}\n")-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=================================================================== short test summary info ====================================================================
ERROR tests/test_case.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
================================================================= 2 warnings, 1 error in 0.48s =================================================================
'allure' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
那么针对这个报错,要如何解决呢?
1. 模块导入错误
报错信息显示 selenium 模块未找到。你需要确保 selenium 安装在你的虚拟环境中。你可以通过以下步骤来解决:
激活你的虚拟环境(假设你的虚拟环境路径是 D:\cekai\xuexi\Tesla.venv):
D:\cekai\xuexi\Tesla\.venv\Scripts\activate
2、安装 selenium 模块:
pip install selenium
如果继续遇到报错:
ERROR: Exception:
Traceback (most recent call last):File "D:\cekai\xuexi\Tesla\.venv\Lib\site-packages\pip\_vendor\urllib3\response.py", line 438, in _error_catcheryieldFile "D:\cekai\xuexi\Tesla\.venv\Lib\site-packages\pip\_vendor\urllib3\response.py", line 561, in readdata = self._fp_read(amt) if not fp_closed else b""^^^^^^^^^^^^^^^^^^File "D:\cekai\xuexi\Tesla\.venv\Lib\site-packages\pip\_vendor\urllib3\response.py", line 527, in _fp_readreturn self._fp.read(amt) if amt is not None else self._fp.read()^^^^^^^^^^^^^^^^^^File "D:\cekai\xuexi\Tesla\.venv\Lib\site-packages\pip\_vendor\cachecontrol\filewrapper.py", line 98, in readdata: bytes = self.__fp.read(amt)^^^^^^^^^^^^^^^^^^^File "D:\python\Lib\http\client.py", line 479, in reads = self.fp.read(amt)^^^^^^^^^^^^^^^^^File "D:\python\Lib\socket.py", line 707, in readintoreturn self._sock.recv_into(b)^^^^^^^^^^^^^^^^^^^^^^^File "D:\python\Lib\ssl.py", line 1253, in recv_intoreturn self.read(nbytes, buffer)^^^^^^^^^^^^^^^^^^^^^^^^^File "D:\python\Lib\ssl.py", line 1105, in readreturn self._sslobj.read(len, buffer)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TimeoutError: The read operation timed outDuring handling of the above exception, another exception occurred:Traceback (most recent call last):File "D:\cekai\xuexi\Tesla\.venv\Lib\site-packages\pip\_internal\cli\base_command.py", line 180, in exc_logging_wrapper^^^^^^^^^^^^^^^File "D:\cekai\xuexi\Tesla\.venv\Lib\site-packages\pip\_internal\cli\req_command.py", line 245, in wrapperreturn func(self, options, args)^^^^^^^^^^^^^^^^^^^^^^^^^File "D:\cekai\xuexi\Tesla\.venv\Lib\site-packages\pip\_internal\commands\install.py", line 377, in runrequirement_set = resolver.resolve(^^^^^^^^^^^^^^^^^File "D:\cekai\xuexi\Tesla\.venv\Lib\site-packages\pip\_internal\resolution\resolvelib\resolver.py", line 179, in resolveself.factory.preparer.prepare_linked_requirements_more(reqs)File "D:\cekai\xuexi\Tesla\.venv\Lib\site-packages\pip\_internal\operations\prepare.py", line 552, in prepare_linked_requirements_moreself._complete_partial_requirements(File "D:\cekai\xuexi\Tesla\.venv\Lib\site-packages\pip\_internal\operations\prepare.py", line 467, in _complete_partial_requirementsfor link, (filepath, _) in batch_download:File "D:\cekai\xuexi\Tesla\.venv\Lib\site-packages\pip\_internal\network\download.py", line 183, in __call__for chunk in chunks:File "D:\cekai\xuexi\Tesla\.venv\Lib\site-packages\pip\_internal\cli\progress_bars.py", line 53, in _rich_progress_barfor chunk in iterable:File "D:\cekai\xuexi\Tesla\.venv\Lib\site-packages\pip\_internal\network\utils.py", line 63, in response_chunksfor chunk in response.raw.stream(File "D:\cekai\xuexi\Tesla\.venv\Lib\site-packages\pip\_vendor\urllib3\response.py", line 622, in streamdata = self.read(amt=amt, decode_content=decode_content)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File "D:\cekai\xuexi\Tesla\.venv\Lib\site-packages\pip\_vendor\urllib3\response.py", line 560, in readwith self._error_catcher():File "D:\python\Lib\contextlib.py", line 158, in __exit__self.gen.throw(value)File "D:\cekai\xuexi\Tesla\.venv\Lib\site-packages\pip\_vendor\urllib3\response.py", line 443, in _error_catcherraise ReadTimeoutError(self._pool, None, "Read timed out.")
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
两种方式解决:
1、使用国内的 PyPI 镜像源
pip install selenium -i https://pypi.tuna.tsinghua.edu.cn/simple
2、设置超时
pip install selenium --timeout=120
3、验证 selenium 是否安装成功:
pip list
4、未知的配置选项警告
在 pytest.ini 文件中有两个未知的配置选项:result_log_verbose 和 xlsx_meta_column_name。这些选项不是 pytest 的标准配置选项,可能是由某些插件或自定义逻辑添加的。你可以通过以下步骤来解决:
1、检查 pytest.ini 文件:
打开 pytest.ini 文件并确认是否有以下内容:
5、allure 命令找不到
安装 allure 命令行工具:
你可以从 Allure2 官方 GitHub 下载适用于你系统的版本。
下载并解压后,将 bin 目录添加到系统的 PATH 环境变量中。
6、再次执行用例
python main.py
可以看到用例运行成功