我试图了解如何在内存 sqlite3 中并行运行 django 测试。
我有具有该结构的 django 应用程序:
gbook
order
...
tests
__init__.py
test_a1.py
test_b1.py
utils.py
Run Code Online (Sandbox Code Playgroud)
test_a1.py 和 test_b1.py 包含相同的代码:
import time
from order import models
from .utils import BackendTestCase
class ATestCase(BackendTestCase):
def test_a(self):
time.sleep(1)
a = models.City.objects.count()
self.assertEqual(a, a)
class BTestCase(BackendTestCase):
def test_b(self):
time.sleep(1)
a = models.City.objects.count()
self.assertEqual(a, a)
Run Code Online (Sandbox Code Playgroud)
utils.py 是:
from django.test import TestCase, Client
from order import models
from django.conf import settings
from order.utils import to_hash
class BackendTestCase(TestCase):
fixtures = ['City.json', 'Agency.json']
def setUp(self):
self.client = Client() …Run Code Online (Sandbox Code Playgroud)