连接到测试数据库的 Pytest 错误

问题描述

我遇到了在运行 pytest 之前从未见过的奇怪错误,我正在运行我的测试,并且由于不允许访问数据库,几乎所有错误都出错了。

这是上周未发生的新错误,因此不是本地代码更改,但我不确定到底发生了什么。

有人能指出我正确的方向吗?

这里是错误:

conftest.py:52: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/local/lib/python3.8/site-packages/django/db/models/query.py:287: in __iter__
    self._fetch_all()
/usr/local/lib/python3.8/site-packages/cacheops/query.py:271: in _fetch_all
    return self._no_monkey._fetch_all(self)
/usr/local/lib/python3.8/site-packages/django/db/models/query.py:1308: in _fetch_all
    self._result_cache = list(self._iterable_class(self))
/usr/local/lib/python3.8/site-packages/django/db/models/query.py:53: in __iter__
    results = compiler.execute_sql(chunked_fetch=self.chunked_fetch,chunk_size=self.chunk_size)
/usr/local/lib/python3.8/site-packages/django/db/models/sql/compiler.py:1154: in execute_sql
    cursor = self.connection.cursor()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <django.test.testcases._DatabaseFailure object at 0x7fb361b2d2b0>

    def __call__(self):
>       raise AssertionError(self.message)
E       AssertionError: Database queries to 'test' are not allowed in this test. Add 'test' to pytest_django.fixtures._django_db_fixture_helper.<locals>.PytestDjangoTestCase.databases to ensure proper test isolation and silence this failure.

/usr/local/lib/python3.8/site-packages/django/test/testcases.py:146: AssertionError
_ ERROR at setup of TestAccountViews.test_can_edit_account_info_with_backticks[admin] _

db = None

    @pytest.fixture
    def slug(db):
        # delete these guys because there should only ever be 1 of each
        from apps.payments.models.ledger_models import TransactionCode
>       for code_object in TransactionCode.objects.all():

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)