[已解决] pytest.main () 打包后,插件参数无法被正确的识别,有大佬碰到过吗

Prince0813 测试交流1 278字数 1197阅读模式

如图,使用 pyinstaller 打包测试后,在调用 pytest.main() 时,运行后提示如下:

文章源自玩技e族-https://www.playezu.com/191723.html

pytest 调用如下:文章源自玩技e族-https://www.playezu.com/191723.html

def m_run(case_path, allure_path, test_count, allure_report_path):
pytest.main(['-v',
'-s',
case_path,
'--alluredir',allure_path,
'--count', str(test_count),
'--repeat-scope=function',
'--disable-warnings',
'--capture=no',
])

pyinstaller 的 spec 文件如下:文章源自玩技e族-https://www.playezu.com/191723.html

block_cipher = None
a = Analysis(['D:\mytools\SmokingTestCase_for_exe\run_ui.py'],
pathex=['C:\Users\Dell','D:\mytools\SmokingTestCase_for_exe',
'D:\mytools\python\python3_7Lib\site-packages'],
binaries=[],
datas=[('D:\mytools\SmokingTestCase_for_exe\testcase\*.py',
'testcase'),
('D:\mytools\SmokingTestCase_for_exe\testdata\*.yaml',
'testdata'),
('D:\mytools\SmokingTestCase_for_exe\page\*.py',
'page'),
('D:\mytools\SmokingTestCase_for_exe\*.py',
'.'),
],
hiddenimports=['page','myemail','mylog'],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='run_ui',
debug=True,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True )

完全没头绪为什么会出现这种情况,去除 -allure 和--count 两个参数就能正常运行,求大佬帮助文章源自玩技e族-https://www.playezu.com/191723.html软件功能测试模板文章源自玩技e族-https://www.playezu.com/191723.html文章源自玩技e族-https://www.playezu.com/191723.html

玩技站长微信
添加好友自动发送入群邀请
weinxin
rainbow-shownow
玩技官方公众号
官方微信公众号
weinxin
PLAYEZU
 
    • FyueC
      FyueC 9

      1想了解下,-allure 和–count 这两个参数,是从什么资料上找到并用来使用的?

      从错误信息上看,程序本身并不支持这两个参数。是这样的 没打包成 exe 的时候用这个 pytest.mian 可以正常运行,然后打包后就这个 main 就不认识这些参数了,–allure 和–count 这两个参数是 pytest 的插件,一个是测试报告的,一个是重复测试用例的,通过 pip 下载的已解决,方法如下:
      根据错误是因为 Pytest 无法识别到命令,具体为什么打包后就识别不到了,这个不得而知,pytest 有添加自定义命令的功能,只需要将用到的命令添加进去让 Pytest 能识别到就好了,需要在 conftest.py 文件中编写,代码如下:
      def pytest_addoption(parser):
      parser.addoption(‘–alluredir’)
      parser.addoption(‘–count’)
      parser.addoption(‘–repeat-scope’)

      你好 我现在也出现了你的打包问题 我想具体咨询下 代码层写不出来能具体看下编译的这块代码吗
      你填的参数是 alluredir ,运行结束,没有生成 allure 报告???求大佬赐教
      这是我的报告路径,求解生成报告不是还要用命令行 allure -o 才能生成?我的都能正常运行 ,你这也没看出什么错误呀我的现在都没有生成 allure 的 json 文件
      您这 conftest.py 文件里面还有什么其他关联性代码吗我把这个文件放在了根目录下
      你的启动命令是这个吗直接双击运行的 exe,你用绝对路径试一下可以加个微信吗 18860888971,我被这个搞得两周了
      这是我的打包命令作者的那个解决方法没有生效唉,我也遇到这个问题了,咋搞。 @FyueC
      1.pytest.main([‘.ApiTestCase’, ‘–alluredir=.ApiTestReport’]) 里边的代码里的 ‘–alluredir=.ApiTestReport’ 删除掉吗
      2.conftest.py 方文件中 只需要增加 parser.addoption(‘–alluredir’) 这个就可以了吗?
      3.在用例函数里还需要写什么代码不?
      请协助回复下,感谢。from allure_pytest import plugin as allure_plugin

      pytest.main(args=your_args, plugins=[allure_plugin])

      spec 打包文件不用加 hiddenimports, 本人亲测,完美解决。楼主的问题我今天遇到了,楼主说的没错是可以解决,但是少了一步啊
      pytest.ini 里要配置一下 addopts = –count 3大佬 –count3 是添加数量是 3 条命令的意思吗这个问题我自己在项目里面建了一个资源文件夹,然后在 spec 里面的 data 中加入了 (‘resource’,’.’),把缺少的第三方插件丢进去在执行 spec 就搞定了问题解决了吗?我也遇到同样的问题

    匿名

    发表评论

    匿名网友
    确定