首页 > 解决方案 > 类内方法的Pytest

问题描述

我有一个 python 代码,我正在尝试为其编写测试。

class ship:
    def __init__(self, draft, crew):
        self.draft = draft
        self.crew = crew

    def is_worth_it(self):
        total_weight_of_crew = (self.crew * 1.5)
        x = (self.draft - total_weight_of_crew)
        if x < 20:
            return False
        else:
            return True

我在下面写了测试,但它似乎不起作用。如何使用来自类的方法的参数编写测试?

def test_is_worth_it(self):
    x = ship(15, 10)
    assert x.is_worth_it() == True

标签: pythonunit-testing

解决方案


推荐阅读