我正在尝试测试我的类(class)中指定的方法。我一直在通过全局执行此操作以传递到我的方法中,例如,
csv.preprocess_col(df, field, remove_invalid_rows_or_raise_exception =0)
使用全局 df 到路径。
但现在我想通过函数传递参数通过执行 test_df(df)
而不是常规 test_df()
来测试我的函数 ( csv.preprocess_col)
在里面,但我一直收到这个 fixture df
not found 错误。
谁知道怎么解决?
只是一个好奇的问题,对于 pytest 来说,可以通过全局将参数传递给函数吗?
最佳答案
pytest 在 several well-integrated ways 中支持测试参数化:
pytest.fixture() allows to define parametrization at the level of fixture functions.
@pytest.mark.parametrize allows to define parametrization at the function or class level, provides multiple argument/fixture sets for a particular test function or class.
pytest_generate_tests enables implementing your own custom dynamic parametrization scheme or extensions.
几个例子 here .
关于python - 如何为pytest传递参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30661605/