I have installed python 3.4.2 and then ran pip install -U pytest
to install 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. How do I get to test my script via IDLE?
UPDATE
I tried to add pytest.main()
, but I received an error.
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.
Check out: http://pytest.org/latest/usage.html#specifying-tests-selecting-tests for some of the different options and the syntax.
Edit: When running in IDLE, you'll also need to start pytest like this: pytest.main("--capture=sys")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.