|
发表于 2025-4-29 15:18:52
|
显示全部楼层
解决打包后参数识别问题的步骤
这个报错通常是因为打包工具(如PyInstaller)未正确捕获pytest插件依赖。按以下步骤操作:
1. 添加隐藏导入
在打包配置中强制包含pytest插件:
- pyinstaller your_script.py \
- --hidden-import allure_pytest \
- --hidden-import _pytest.hookspec \
- --hidden-import _pytest.config \
- --hidden-import _pytest.assertion
复制代码
2. 添加钩子文件
创建 hook-pytest.py 文件:
- from PyInstaller.utils.hooks import collect_submodules
- hiddenimports = collect_submodules('pytest')
复制代码
打包时添加 --additional-hooks-dir=.
3. 包含数据文件
在spec文件中添加:
- a = Analysis(
- ...
- datas=[
- ('pytest.ini', '.'),
- ('allure-report/**/*', 'allure-report')
- ],
- ...
- )
复制代码
4. 建议的完整打包命令
- pyinstaller your_script.spec \
- --onefile \
- --hidden-import allure_pytest \
- --additional-hooks-dir=.
复制代码
5. 验证打包结果
解压/运行后检查是否包含:
- pytest.ini
- allure-pytest包文件
- _pytest相关模块
提示:如果使用cx_Freeze等其他打包工具,需要对应配置include_files参数。建议优先使用PyInstaller+spec文件方案。
以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。 |
|