- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有这段 Python 代码:
import pytest
class Apple:
@pytest.mark.parametrize("kind", ['fruit', 'veg', 'nuts'])
def mix_kind_and_colour(self, kind):
print(kind)
return self
def runner():
return Apple.mix_kind_and_colour()
if __name__== "__main__":
runner()
但是我得到这个错误:
TypeError: mix_kind_and_colour() missing 2 required positional arguments: 'self' and 'kind'
我该如何解决?
最佳答案
Please have look at pytest's docu, it's quite fine.
在您想要对测试进行分组之前,您不需要类(class)。
但你需要遵循一些naming conventions .
用于从终端运行 pytest
命令的 test_sample.py 的一个简单工作示例是:
import pytest
@pytest.mark.parametrize("kind", ['fruit', 'veg', 'nuts'])
def test_mix_kind_and_colour(kind):
print(kind)
如果你想使用一个类尝试运行 pytest
for:
import pytest
class TestApple:
@pytest.mark.parametrize("kind", ['fruit', 'veg', 'nuts'])
def test_mix_kind_and_colour(self, kind):
print(kind)
但您还需要一些 assertions为了测试什么?!?
# content of test_assert1.py
def f():
return 3
def test_function():
assert f() == 4
关于python - 为什么在调用方法时无法识别 Pytest Parametrize?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53867229/
使用 python 3.8 和 pytest 5.3.2 在 conftest.py 中,我有一个从 json 配置文件读取数据的装置,为了在多个测试中重用从 json 配置文件中读取的数据。 配置.
我想知道是否可以使用 given 参数来自 pytest 的 parametrize 函数。 示例: import pytest from hypothesis import given from h
我正在尝试创建一个 PowerShell 脚本,该脚本将部署 Azure 开发测试实验室的实例,在那里创建一个环境,以及 databricks、azure 数据工厂等资源。这是我负责的实验室模板的一部
我有这段 Python 代码: import pytest class Apple: @pytest.mark.parametrize("kind", ['fruit', 'veg', 'nu
我隐含地把它变成了一个社区维基,因为答案可能非常广泛。我正在与一家初创公司合作以实现以下目标。 在医学研究中,患者的医疗记录可以包含关于患者特定诊断的无限量数据,例如吸烟者患肺癌的几率更高,但这并不一
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
我有一个带有非常大集合的 mongo 数据库,我需要用 Pytest 对其运行测试。我正在尝试使用 mark.parametrize dectorator 但使用 pymongo.cursor Cur
我希望一个参数化依赖于一个较早的参数化: @pytest.mark.parametrize("locale_name", LOCALES) @pytest.mark.parametrize("mone
我有多个函数可以引发 ValueError 来测试。到目前为止,我的解决方案是: import pytest import record @pytest.fixture(name='raised')
我基于 ReaderT design pattern 构建了一个项目.我没有使用类型类方法进行依赖注入(inject),而是选择使用简单的处理程序注入(inject)作为函数参数。这部分工作正常,因为
是否可以创建一个可以使用的 Extractor 对象,例如: val x = 42 x match { case GreaterThan(80) => println("5") case Gr
我有一个测试功能,可以修补一些东西。一旦我达到超过 2 或 3 个补丁,功能开始看起来很糟糕 def test_bla(): with patch(...): with pat
我有一个测试功能,可以修补一些东西。一旦我达到超过 2 或 3 个补丁,功能开始看起来很糟糕 def test_bla(): with patch(...): with pat
我有一个遗留接口(interface),它以字符串的形式为我提供实例类型,例如“int”、“float”等。 我想出了这两个函数来解决这个问题: template T type_factory(co
当参数化引发预期异常的测试时,我一直使用以下形式: import pytest class SomeException(Exception): pass class AnotherExcept
有没有办法将可调用指定为pytest.mark.parametrize()参数,以便仅在测试时动态生成参数选择运行? 为了生成参数,我需要执行一些昂贵的操作,并且我只想在选择运行测试时执行这些操作。
我正在尝试将三个不同的固定装置传递给我的 pytest.mark.parameterize 装饰器,如下所示: @pytest.mark.parametrize("credentials, retur
从文档SpannerQueryDatabaseInstanceOperator接受查询参数。然而,没有像PostgresOperator这样聪明的东西,它也接受一个parameters参数来使用占位符
我有一个函数可以读取 yaml 文件并生成测试迭代作为字典列表,如下所示: Iterations = lib_iterations() print Iterations Iterations = [{
Sample_test.py @pytest.mark.parametrize(argnames="key",argvalues=ExcelUtils.getinputrows(__name__),s
我是一名优秀的程序员,十分优秀!