我有一个Django应用程序,我正在尝试使用pytest和pytest-django测试它。但是,通常情况下,当测试运行完毕时,我会得到数据库删除失败的错误:DETAIL: There is 1 other session using the database.
基本上,我能缩小范围的最小测试代码是:
@pytest.fixture
def make_bundle():
a = MyUser.objects.create(key_id=uuid.uuid4())
return a
class TestThings:
def test_it(self, make_b
为什么在点击"Create New Test..:“时,PyCharm会生成以下代码模板,尽管我将pytest作为默认的测试运行器? 如果我的函数是create_training_data,那么PyCharm将为此生成以下代码: from unittest import TestCase
class TestCreate_training_data(TestCase):
def test_create_training_data(self):
self.fail() 然而,pytest既不需要导入,也不需要子类化, class TestCreate_training
我的conftest.py中有下面的代码
import pytest
@pytest.fixture(scope="class")
def fix1():
print("i am in fix1")
a = 10
return a
@pytest.fixture(scope="class")
def fix2():
print("i am in fix2")
b = 20
return b
@pytest.fixture(scope="session",autouse=Tru
我使用的是Nunit 3.12,我想从脚本中运行我的测试的各个子集。例如,我知道Nunit支持各种属性,我可以使用Visual Studio中的测试窗口或测试播放列表来运行各种类。 但是,是否可以通过脚本指定测试的子集并从命令行执行?Nunit控制台似乎是一个控制台测试运行器,但还不清楚它是否打算用于这种脚本使用。在Python和Pytest中,您可以运行run pytest from a Python script,而在Java语言中,您可以使用Junit从gradle job或on the command line with an argument file运行特定的类。 我之所以想知道
在Django应用程序的测试运行中使用pytest/pytest-django时,如何将数据持久化到DB?
我使用py.test --nomigrations --reuse-db -s运行pytest,Postgres DB test_<configued_db_name>如预期的那样被创建,但是在测试之间似乎没有任何东西被持久保存到DB中,并且在测试运行结束时DB是空的。
import pytest
from django.contrib.auth.models import User
@pytest.mark.django_db(transaction=False)
de