我上这个班:
在接受.py在
class AcceptC(object):
def __init__(self):
self.minimum = 30
self.maximum = 40
以及单元测试:
接受_测试.py在
^{pr2}$使用pytest运行时,我收到一个错误:
NameError: name 'self' is not defined
我还看到我不能在测试函数中使用self
作为参数。在
最后,有没有办法避免使用:
expected_min = self.accept.minimum
expected_max = self.accept.maximum
并立即使用self.accept.minimum
?在
如果我使用self
作为测试函数的参数,它将返回:
fixture 'self' not found
您的方法中缺少
self
(假设它是一个方法,如果它是一个函数,则需要先使它成为TestAcceptC
的方法)参数列表:应该是(我做了一些额外的改变;远离}-类):
^{pr2}$unittest
和更多{问题仅仅是因为:
这个遗产unittest.TestCase会破坏pytest固定装置的“自我”。在
信息:https://docs.pytest.org/en/3.0.1/unittest.html
相关问题 更多 >
编程相关推荐