From 6a308179ad94f3d1af0531154fc95668db532ee3 Mon Sep 17 00:00:00 2001 From: hub-gif <2487812171@qq.com> Date: Fri, 17 Apr 2026 14:56:35 +0800 Subject: [PATCH] =?UTF-8?q?test(pipeline):=20=E5=9C=A8=20tests/conftest=20?= =?UTF-8?q?=E4=B8=AD=20django.setup=20=E4=BB=A5=E4=BF=AE=E5=A4=8D=E6=94=B6?= =?UTF-8?q?=E9=9B=86=E9=98=B6=E6=AE=B5=20AppRegistryNotReady?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pytest 收集含 pipeline.jd.runner 的测试时须先加载 Django;全量 pipeline/tests 现可一次跑通。 Made-with: Cursor --- backend/pipeline/tests/conftest.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 backend/pipeline/tests/conftest.py diff --git a/backend/pipeline/tests/conftest.py b/backend/pipeline/tests/conftest.py new file mode 100644 index 0000000..a0d8efc --- /dev/null +++ b/backend/pipeline/tests/conftest.py @@ -0,0 +1,10 @@ +"""在收集本目录测试模块之前初始化 Django,避免 ``import pipeline.jd.runner`` 触发 AppRegistryNotReady。""" +from __future__ import annotations + +import os + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings") + +import django # noqa: E402 + +django.setup()