我想在conftest.py中设置一个固定设备,并与我的所有测试共享它。但是,在下面的最小示例中运行pytest时,我会遇到以下错误:
ERROR at setup of test_test
Fixture "pytest_runtest_setup" called directly. Fixtures are not meant to be called directly,
but are created automatically when test functions request them as parameters.
conftest.py
import pyte
我正在尝试将py.test的与我的单元测试结合在一起,与unittest一起使用。我在项目的顶层(如描述的)将几个夹具放在conftest.py文件中,用@pytest.fixture装饰它们,并将它们的名称作为需要它们的测试函数的参数。
安装程序注册正确,如py.test --fixtures test_stuff.py所示,但是当我运行py.test时,我得到了NameError: global name 'my_fixture' is not defined。这似乎只有在我使用unittest.TestCase-but的子类时才会发生-- py.test文档似乎说它与un
我有一个测试,它迭代从fixture返回的字典列表(解析自S3中的csv文件)并执行断言。 在伪代码中: # s_3 is a fixture
def my_fixture(s_3):
s_3.get_data_from_s3()
yield s_3_data_as_list_of_dicts
def my_test(my_fixture):
for entry in my_fixture:
do my assertions 我还在将输出传入@pytest.mark.parametrize的地方编写了这段代码,但它不是来自fixture,而是来自我必须实例化/连接S3的
我正在使用Django,并想用pytest、pytest-django、pytest-factoryboy和pytest-lazyfixtures编写一个测试。
我有使用多表继承的Django模型,如下所示:
class User(models.Model):
created = models.DateTimeField()
active = models.BooleanField()
class Editor(User):
pass
class Admin(User):
pass
我还为所有型号建立了工厂,并对它们进行了登记,例如:
class UserFa
我的主文件中有一个全局对象。
# reporter.py
from os import environ
from influxdb import InfluxDBClient
influxdb_client = InfluxDBClient(host=environ['INFLUXCLOUD_HOST'],
username=environ['INFLUXCLOUD_USERNAME'],
password=environ[