我正在研究密码-dojo网球卡塔,我被最愚蠢的问题困住了。在运行文件中的第一个测试之后,我的pytest就停止了。我的测试文件如下所示:
from tennis import game
import re
def test_game_start(capsys):
MaxVsMimi = game()
MaxVsMimi.result()
out, err = capsys.readouterr()
assert bool(re.search(r'Love : Love', out))
def p1_scores_once(capsys):
MaxVsMimi = game()
MaxVsMimi.score("p1")
MaxVsMimi.result()
out, err = capsys.readouterr()
assert bool(re.match(r'^abc', out))这是代码:
class game:
def __init__(self):
self.scorep1 = "Love"
self.scorep2 = "Love"
def result(self):
print(self.scorep1, ":", self.scorep2)以及产出:
:stdout:
============================= test session starts ==============================
platform linux -- Python 3.8.6, pytest-6.0.2, py-1.9.0, pluggy-0.13.1 -- /usr/local/bin/python
cachedir: .pytest_cache
rootdir: /sandbox
collecting ... collected 1 item
test_tennis.py::test_game_start PASSED [100%]
============================== 1 passed in 0.01s ===============================为什么它不运行第二个"p1_scores_once“测试?
谢谢!
发布于 2020-11-13 15:42:48
与许多测试库(包括unittest )一样,Pytest要求所有测试函数的名称开头都有单词test。只需更改p1_scores_once的名称,就可以修复代码。
def test_p1_scores_once(capsys):
...现在,自动测试发现系统将把这个功能当作一个测试用例.
https://stackoverflow.com/questions/64823700
复制相似问题