Pytest 装置跳过测试

Dev*_*ech 0 python pytest pytest-django pytest-fixtures

我有这个工厂如图:


@pytest.fixture
def user_factory(db):
    def create_app_user(
            username: str,
            password: str = None,
            first_name: str = "firstname",
            last_name: str = "lastname",
            email: str = "user@g.com",
            is_staff: str = False,
            is_superuser: str = False,
            is_active: str = True
    ):
        user_f = User.objects.create_user(
            username = username,
            password = password,
            first_name = first_name,
            last_name = last_name,
            email = email,
            is_staff = is_staff,
            is_superuser = is_superuser,
            is_active = is_active
        )
        return user_f
    return create_app_user


@pytest.fixture
def new_user(db, user_factory):
    return user_factory("myusername", "mypassword", "myfirstname")

Run Code Online (Sandbox Code Playgroud)

我尝试使用工厂来运行位于 test_name.py 文件中的测试:


def create_new_user(new_user):
    print(new_user.first_name)
    assert new_user.first_name == "myfirstname"

Run Code Online (Sandbox Code Playgroud)

但是,测试没有运行,也没有产生错误消息。正如文档中提到的,我的工厂位于 conftest.py 文件的根目录中。我的 pytest.ini 文件中也有此设置: python_files = tests.py test_*.py *_test.py

请问可能发生了什么?

小智 6

函数的名称也应符合约定(test_*)。