python - 类内方法的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
解决方案
推荐阅读
- postgresql - postgres物化视图并行刷新
- python - 在 python 中的 MS SQL SERVER 中加载选定的 DataFrame 列
- d3.js - 在 d3 中,如何将包括超链接在内的多段文本放入 rect div?
- go - 为什么 goroutine 只作为等待组的一部分运行一次
- javascript - 如何使用表中的检查值使用javascript制作另一个表
- php - 拒绝用户“SELECT * FROM users”访问,但它不是用户
- onesignal - 我应该在 laravel 7 中将 https 站点的 oneSignal SDK 文件放在哪里以及如何在刀片文件中引用它们?
- google-apps-script - 如何在 Google 表格的特定列中获取最后填充的行?
- python - 如何获取另一列中每个值的列中值的平均值
- excel - 在范围内的任何单元格中查找值