python:我在测试代码中做错了什么?
我想知道我做错了什么python:我在测试代码中做错了什么?,python,testing,enums,auto,Python,Testing,Enums,Auto,我想知道我做错了什么 from enum import Enum, auto class colors(Enum): red= auto() green= auto() yellow= auto() 这是我的课 def is_first(self): return self is not colors.red 我的第一个功能 def second(self): if self is colors.red:
from enum import Enum, auto
class colors(Enum):
red= auto()
green= auto()
yellow= auto()
这是我的课
def is_first(self):
return self is not colors.red
我的第一个功能
def second(self):
if self is colors.red:
return ''
elif self is green:
return 'second_type'
elif self is yellow:
return 'third_type'
我在测试中做错了什么?我需要让他们全部通过
@pytest.mark.parametrize('input_str, expected_result',
[('aa', False)])
def test_is_first(input_str, expected_result):
assert is_first(input_str) is expected_result
还有我的第二个功能
@pytest.mark.parametrize('input_str, expected_result',
[('', True),
('second_type', True),
('third_type', True),
('aa', False)])
def test_second(input_str, expected_result):
assert second(input_str) is expected_result
你写道:
def second(self):
if self is colors.red:
return ''
elif self is green:
return 'second_type'
elif self is yellow:
return 'third_type'
这将通过测试:
def second(self):
if self == '':
return True
elif self == 'second_type':
return True
elif self == 'third_type':
return True
elif self 'aa':
return False
您的
assert是\u first(输入\u str)是预期的\u结果将失败
def is_first(self):
return self is not colors.red
这将返回True
或False
。您的预期结果是根据字符串检查布尔值。我调整了答案。您应该查找基本的pytest模板。您仍然遗漏了很多代码。所以仅仅复制粘贴并不能解决您的问题。在应用测试之前,您应该了解测试实际上是如何工作的。
def is_first(self):
return self is not colors.red