DatabaseError: Объекты базы данных, созданные в потоке, могут использоваться только в том же потокеPython

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 DatabaseError: Объекты базы данных, созданные в потоке, могут использоваться только в том же потоке

Сообщение Anonymous »

У меня есть следующая проблема, когда я пытаюсь выполнить свои тесты django :
/Users/myUser/Desktop/myProject-py/src/project/project/billing_v2/tests/test_accounting_integration_heading.py::AccountingIntegrationHeadingAPITests::test_create_accounting_integration_heading failed with error: Test failed with exception
request =
django_db_blocker =
@pytest.fixture(autouse=True, scope="class")
def _django_setup_unittest(
request,
django_db_blocker: "_DatabaseBlocker",
) -> Generator[None, None, None]:
"""Setup a django unittest, internal to pytest-django."""
if not django_settings_is_configured() or not is_django_unittest(request):
yield
return

# Fix/patch pytest.
# Before pytest 5.4: https://github.com/pytest-dev/pytest/issues/5991
# After pytest 5.4: https://github.com/pytest-dev/pytest-django/issues/824
from _pytest.unittest import TestCaseFunction
original_runtest = TestCaseFunction.runtest

def non_debugging_runtest(self) -> None:
self._testcase(result=self)

try:
TestCaseFunction.runtest = non_debugging_runtest # type: ignore[assignment]

> request.getfixturevalue("django_db_setup")
.venv/lib/python3.8/site-packages/pytest_django/plugin.py:490:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.venv/lib/python3.8/site-packages/pytest_django/fixtures.py:122: in django_db_setup
db_cfg = setup_databases(
.venv/lib/python3.8/site-packages/django/test/utils.py:179: in setup_databases
connection.creation.create_test_db(
.venv/lib/python3.8/site-packages/django/db/backends/base/creation.py:59: in create_test_db
self.connection.close()
.venv/lib/python3.8/site-packages/django/utils/asyncio.py:33: in inner
return func(*args, **kwargs)
.venv/lib/python3.8/site-packages/django/db/backends/base/base.py:285: in close
self.validate_thread_sharing()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self =
def validate_thread_sharing(self):
"""
Validate that the connection isn't accessed by another thread than the
one which originally created it, unless the connection was explicitly
authorized to be shared between threads (via the `inc_thread_sharing()`
method). Raise an exception if the validation fails.
"""
if not (self.allow_thread_sharing or self._thread_ident == _thread.get_ident()):
> raise DatabaseError(
"DatabaseWrapper objects created in a "
"thread can only be used in that same thread. The object "
"with alias '%s' was created in thread id %s and this is "
"thread id %s."
% (self.alias, self._thread_ident, _thread.get_ident())
)
E django.db.utils.DatabaseError: DatabaseWrapper objects created in a thread can only be used in that same thread. The object with alias 'default' was created in thread id 8482561792 and this is thread id 13188866304.
.venv/lib/python3.8/site-packages/django/db/backends/base/base.py:552: DatabaseError
< /code>
Однако эта проблема возникает только тогда, когда я пытаюсь выполнить все мои тесты одновременно, если я выполняю их один за другим или модулем по модулю, все это хорошо. < /p>
Версии
django - 3.2.25
python - 3.8.20 < /p>
my db настрой Настройки."ENGINE": "django.contrib.gis.db.backends.postgis",
< /code>
! Обновление !:
Я только что понял, что проблема возникает только тогда, когда я запускаю все свои тесты из кода Visual Studio - Test Explorer. Если я запускаю их вручную с терминала, используя следующую команду:
`` `pytest -v src/project`` - у меня нет проблем .. Как бы я ни хотел запустить это, используя IDE также ..


Подробнее здесь: https://stackoverflow.com/questions/797 ... -used-in-t
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Python»