问题描述:在源程序中运行 pytest.main(['.\ApiTestCase', '--alluredir=\ApiTestReport', '--clean-alluredir']) 可以正常执行,在使用 pyinstaller -F Auto_Runner_Api_Main.py 生成的
Auto_Runner_Api_Main.exe 程序执行时报如下错误:
ERROR: usage: Auto_Runner_Api_Main.exe [options] [file_or_dir] [file_or_dir] [...]
Auto_Runner_Api_Main.exe: error: unrecognized arguments: --alluredir=\ApiTestReport --clean-alluredir
inifile: None
rootdir: C:\Users\oscar\eclipse-workspace\AutoRunner_ApiPlatform\src\dist
注:本机已按装 allure-pytest 插件,将参数'--alluredir=\ApiTestReport', '--clean-alluredir'去掉打包成 exe 可以正常运行,难道 allure_pytest 包没打进去吗
我也遇到同样的问题了,貌似打包时未将 pytets、allure 打包进去,查询之后将 pytest、allure 强制添加打包进去,也不行,希望有知道的帮忙指点一下,多谢啦!
加个 --onefile 试试?
for example:
PyInstaller.main.run([
'--name=%s' % package_name,
'--onefile',
# '--windowed',
os.path.join(os.getcwd(), 'main.py'),
])
自己顶下!
顶,哪位帮忙给解决下,多谢啦!
from allure_pytest import plugin as allure_plugin
pytest.main(args=your_args, plugins=[allure_plugin])
spec 打包文件不用加 hiddenimports, 本人亲测,完美解决。
from allure_pytest import plugin as allure_plugin
args = ['-s', '-q', test_case_path, '--alluredir', xml_report_path]
pytest.main(args=args , plugins=[allure_plugin])
'--alluredir=./report/xml'参数 不能去掉呢。
还是不行哦,跟版本有没有关系呢,这是报错详情,方便的话加哈微信指导下,多谢啦,18602959120
Traceback (most recent call last):
File "D:/Workspace/WEB_Project/run.py", line 63, in
run()
File "D:/Workspace/WEB_Project/run.py", line 36, in run
pytest.main(args=args, plugins=[allure_plugin])
File "D:\Python\Python37\Lib\site-packages_pytest\config_init.py", line 58, in main
config = _prepareconfig(args, plugins)
File "D:\Python\Python37\Lib\site-packages_pytest\config__init.py", line 196, in _prepareconfig
pluginmanager=pluginmanager, args=args
File "D:\Python\Python37\Lib\site-packages\pluggy\hooks.py", line 289, in __call_
return self.hookexec(self, self.get_hookimpls(), kwargs)
File "D:\Python\Python37\Lib\site-packages\pluggy\manager.py", line 87, in _hookexec
return self._inner_hookexec(hook, methods, kwargs)
File "D:\Python\Python37\Lib\site-packages\pluggy\manager.py", line 81, in
firstresult=hook.spec.opts.get("firstresult") if hook.spec else False,
File "D:\Python\Python37\Lib\site-packages\pluggy\callers.py", line 203, in _multicall
gen.send(outcome)
File "D:\Python\Python37\Lib\site-packages_pytest\helpconfig.py", line 93, in pytest_cmdline_parse
config = outcome.get_result()
File "D:\Python\Python37\Lib\site-packages\pluggy\callers.py", line 80, in get_result
raise ex[1].with_traceback(ex[2])
File "D:\Python\Python37\Lib\site-packages\pluggy\callers.py", line 187, in _multicall
res = hook_impl.function(*args)
File "D:\Python\Python37\Lib\site-packages_pytest\config__init.py", line 675, in pytest_cmdline_parse
self.parse(args)
File "D:\Python\Python37\Lib\site-packages_pytest\config__init.py", line 854, in parse
self._preparse(args, addopts=addopts)
File "D:\Python\Python37\Lib\site-packages_pytest\config__init.py", line 808, in _preparse
self.pluginmanager.load_setuptools_entrypoints("pytest11")
File "D:\Python\Python37\Lib\site-packages\pluggy\manager.py", line 293, in load_setuptools_entrypoints
self.register(plugin, name=ep.name)
File "D:\Python\Python37\Lib\site-packages_pytest\config__init.py", line 306, in register
ret = super(PytestPluginManager, self).register(plugin, name)
File "D:\Python\Python37\Lib\site-packages\pluggy\manager.py", line 100, in register
% (plugin_name, plugin, self._name2plugin)
ValueError: Plugin already registered: allure_pytest=
{'127516568': <_pytest.config.PytestPluginManager object at 0x000000000799BF98>, 'pytestconfig': <_pytest.config.Config object at 0x00000000079BEA20>, 'mark': <module '_pytest.mark' from 'D:\Python\Python37\Lib\site-packages\_pytest\mark\__init.py'>, 'main': , 'terminal': , 'runner': , 'python': , 'fixtures': , 'debugging': , 'unittest': , 'capture': , 'skipping': , 'tmpdir': , 'monkeypatch': , 'recwarn': , 'pastebin': , 'helpconfig': , 'nose': , 'assertion': <module '_pytest.assertion' from 'D:\Python\Python37\Lib\site-packages\_pytest\assertion\__init_.py'>, 'junitxml': , 'resultlog': , 'doctest': , 'cacheprovider': , 'freeze_support': , 'setuponly': , 'setupplan': , 'stepwise': , 'warnings': , 'logging': , 'allure_pytest.plugin': }
Process finished with exit code 1
@ang 您好
使用
1.导入 from allure_pytest import plugin as allure_plugin
2.pytest.main(args=args , plugins=[allure_plugin])
运行后报插件 plugin 已经注册过了呢!
ValueError: Plugin already registered: allure_pytest=
{'42511272': <pytest.config.PytestPluginManager object at 0x000000000288ABA8>, 'pytestconfig': <_pytest.config.Config object at 0x000000000D0657F0>, 'mark': <module '_pytest.mark' from 'C:\Python36\lib\site-packages\_pytest\mark\__init.py'>, 'main': , 'runner': , 'fixtures': , 'helpconfig': , 'python': , 'terminal': , 'debugging': , 'unittest': , 'capture': , 'skipping': , 'tmpdir': , 'monkeypatch': , 'recwarn': , 'pastebin': , 'nose': , 'assertion': <module '_pytest.assertion' from 'C:\Python36\lib\site-packages\_pytest\assertion\__init_.py'>, 'junitxml': , 'resultlog': , 'doctest': , 'cacheprovider': , 'freeze_support': , 'setuponly': , 'setupplan': , 'stepwise': , 'warnings': , 'logging': , 'reports': , 'faulthandler': , 'allure_pytest.plugin': }
要打包程序后再测试, 没有打包的话,就会提示已经注册了。
还有我是把程序打包成文件夹的, 打包成单个 exe 文件的情况没有测试过。
@lang lang 感谢,已成功解决!
@lang @oscarforever 大佬再请教你个问题,在打包成 exe 之后,单独通过 exe 执行(脱离.py 文件)时,发现测试脚本无法找到 fixture,希望大佬可以帮忙解答下,多谢啦!
已将 conftest.py 文件进行过打包
这个原因我也不清楚。但是按照我的理解,test 文件夹是可以不用打包到 exe 文件中的。因为你的 test 文件夹是需要经常更新的,比如说添加测试用例等等情况,所以 test 文件夹不打包到 exe 文件中,反而是比较合理的。
通过 pyinstaller 打包 pytest, 怎么解决对 pytest, 以及指定文件下的用例的依赖呢?我现在是需要 pytest ./testfolder 来执行一个文件夹下面的所有用例。