gpt4 book ai didi

python - 如何在 PyScripter 中运行 Py.test

转载 作者:行者123 更新时间:2023-11-28 16:46:27 25 4
gpt4 key购买 nike

我是 py.test 的新手,请告诉我如何在 PyScripter 编辑器中运行 py.test。我已经尝试过 belwo 方式,但它不起作用。

导入测试

定义函数(x): 返回 x + 1

def test_answer(): 断言 func(3) == 5

pytest.main()

在运行上面的脚本时我得到一个错误提示

Traceback (most recent call last):
File "<module1>", line 10, in <module>
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", line 474, in main
exitstatus = config.hook.pytest_cmdline_main(config=config)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", line 422, in __call__
return self._docall(methods, kwargs)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", line 433, in _docall
res = mc.execute()
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", line 351, in execute
res = method(**kwargs)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\main.py", line 107, in pytest_cmdline_main
return wrap_session(config, _main)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\main.py", line 92, in wrap_session
config.pluginmanager.notify_exception(excinfo, config.option)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", line 285, in notify_exception
res = self.hook.pytest_internalerror(excrepr=excrepr)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", line 422, in __call__
return self._docall(methods, kwargs)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", line 433, in _docall
res = mc.execute()
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\core.py", line 351, in execute
res = method(**kwargs)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\terminal.py", line 152, in pytest_internalerror
self.write_line("INTERNALERROR> " + line)
File "C:\Python27\lib\site-packages\pytest-2.3.2-py2.7.egg\_pytest\terminal.py", line 140, in write_line
self._tw.line(line, **markup)
File "C:\Python27\lib\site-packages\py-1.4.11-py2.7.egg\py\_io\terminalwriter.py", line 181, in line
self.write(s, **kw)
File "C:\Python27\lib\site-packages\py-1.4.11-py2.7.egg\py\_io\terminalwriter.py", line 225, in write
self._file.write(msg)
File "C:\Python27\lib\site-packages\py-1.4.11-py2.7.egg\py\_io\terminalwriter.py", line 241, in write
self._writemethod(data)
TypeError: 'AsyncStream' object is not callable

请帮帮我

最佳答案

脚本似乎是错误的,据我所知,如果您希望 pytest 应该由 python 解释器运行,可以使用 pytest.main。您需要在一个目录下进行测试。例如,您的 pytest 文件名为 test_sample,其中包含以下内容===================================pytests/test_sample============ ===================

    import pytest
def func(x): return x + 1
def test_answer(): assert func(3) == 5

============================================= ===================================然后你可以在运行你的 test_sample 的 python 文件中包含以下代码

   pytest.main(args=['-s', os.path.abspath('pytests')])

这应该可以解决您的问题

如果您不想让 python 运行您的 pytests,您可以通过 tools-->configure tools 将 pyscripter runner 配置为由 pytests 运行,然后添加 pytests 命令行参数。然后你可以从工具运行 pytest。默认情况下,pyscripter 使用 python 解释器作为运行器

关于python - 如何在 PyScripter 中运行 Py.test,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13374267/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com