首页 > 解决方案 > PyTest shows a wrong answer

问题描述

Can you guys tell me what am I doing wrong with my unit testing?

class Blizzard(Storm):
    def __init__(self, name, wind_speed, temp):
        self.temp = temp
        super().__init__(name, wind_speed)

    def calculate_classification(self) -> str:
        if self.wind_speed >= 35:
            return "Blizzard"
        elif self.wind_speed >= 45 and self.temp <= -12:
            return "Severe Blizzard"
        return "Snow Storm"

Here is my class to check what kind of blizzard is there and below you can see my unit test code:

def test_severe_blizzard():
    b1 = Blizzard("Wendy", 46, -12)
    assert b1.calculate_classification() == 'Severe Blizzard'

Here is the output

标签: pythonpytest

解决方案


The wind speed is greater than 35 so it returns the first if statement.


推荐阅读