简体   繁体   English

通过IDLE gui运行pytest

[英]Run pytest via IDLE gui

I have installed python 3.4.2 and then ran pip install -U pytest to install pytest. 我已经安装了python 3.4.2,然后运行pip install -U pytest来安装pytest。

I have the following example script: 我有以下示例脚本:

# content of test_sample.py
import pytest

def func(x):
    return x + 1

def test_answer():
    assert func(3) == 4

When I press F5 in IDLE it doesn't seem to run anything. 当我在IDLE中按F5时,似乎没有任何运行。 How do I get to test my script via IDLE? 如何通过IDLE测试脚本?

UPDATE UPDATE
I tried to add pytest.main() , but I received an error. 我尝试添加pytest.main() ,但是收到错误消息。

File "C:\Python34\lib\site-packages\_pytest\config.py", line 32, in main
    config = _prepareconfig(args, plugins)
  File "C:\Python34\lib\site-packages\_pytest\config.py", line 85, in _prepareconfig
    pluginmanager=pluginmanager, args=args)
  File "C:\Python34\lib\site-packages\_pytest\core.py", line 413, in __call__
    return self._docall(methods, kwargs)
  File "C:\Python34\lib\site-packages\_pytest\core.py", line 424, in _docall
    res = mc.execute()
  File "C:\Python34\lib\site-packages\_pytest\core.py", line 315, in execute
    res = method(**kwargs)
  File "C:\Python34\lib\site-packages\_pytest\helpconfig.py", line 27, in pytest_cmdline_parse
    config = __multicall__.execute()
  File "C:\Python34\lib\site-packages\_pytest\core.py", line 315, in execute
    res = method(**kwargs)
  File "C:\Python34\lib\site-packages\_pytest\config.py", line 636, in pytest_cmdline_parse
    self.parse(args)
  File "C:\Python34\lib\site-packages\_pytest\config.py", line 747, in parse
    self._preparse(args)
  File "C:\Python34\lib\site-packages\_pytest\config.py", line 719, in _preparse
    args=args, parser=self._parser)
  File "C:\Python34\lib\site-packages\_pytest\core.py", line 413, in __call__
    return self._docall(methods, kwargs)
  File "C:\Python34\lib\site-packages\_pytest\core.py", line 424, in _docall
    res = mc.execute()
  File "C:\Python34\lib\site-packages\_pytest\core.py", line 315, in execute
    res = method(**kwargs)
  File "C:\Python34\lib\site-packages\_pytest\capture.py", line 49, in pytest_load_initial_conftests
    capman.init_capturings()
  File "C:\Python34\lib\site-packages\_pytest\capture.py", line 78, in init_capturings
    self._capturing.start_capturing()
  File "C:\Python34\lib\site-packages\_pytest\capture.py", line 257, in start_capturing
    self.in_.start()
  File "C:\Python34\lib\site-packages\_pytest\capture.py", line 345, in start
    raise ValueError("saved filedescriptor not valid anymore")
ValueError: saved filedescriptor not valid anymore

Try adding pytest.main() to the bottom of the script. 尝试将pytest.main()添加到脚本底部。

Check out: http://pytest.org/latest/usage.html#specifying-tests-selecting-tests for some of the different options and the syntax. 请访问: http : //pytest.org/latest/usage.html#specifying-tests-selecting-tests了解一些不同的选项和语法。

Edit: When running in IDLE, you'll also need to start pytest like this: pytest.main("--capture=sys") 编辑:在IDLE中运行时,还需要像这样启动pytest: pytest.main("--capture=sys")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过 pytest.main() 运行时以编程方式检索 pytest 结果 - retrieve pytest results programmatically when run via pytest.main() pytest通过配置文件运行标记 - pytest run markers via configuration file Python脚本无法通过TextMate运行,在IDLE和Eclipse中可以正常运行 - Python Script Won't Run Via TextMate, OK in IDLE and Eclipse Pytest插件打开GUI - Pytest plugin opening GUI 如何使用运行模块功能在Komodo IDE中像在IDLE(Python GUI)中一样运行python程序? - How can I run a python program in Komodo IDE like in IDLE(Python GUI) using Run Module feature? 如何通过 pytest(和夹具)并行运行 Spark 单元测试? - How to run Spark unit testing in parallel via pytest (and fixture)? 为什么 tkinter 模块在通过命令行运行时会引发属性错误,但在通过 IDLE 运行时不会引发属性错误? - Why tkinter module raises attribute error when run via command line but not when run via IDLE? 我如何在IDLE之外运行.py(GUI)文件以使用sys.exit - How do I run a .py(GUI) file outside of IDLE in order to use sys.exit 当我运行它们时,IDLE Tkinter GUI小部件将无法打开? (Windows 7的) - IDLE Tkinter GUI widgets won't open when I run them? (Windows 7) 如何判断python脚本是在终端中运行还是通过GUI运行? - How to tell if python script is being run in a terminal or via GUI?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM