我正在为一个用 Python3.6/Django 2.0 制作的 web 应用程序编写测试,我有以下情况:
class TestFoo(TestCase):
def test_a(self):
obj = Foo.objects.create(a = "bar")
expectation = {"a" : "bar"}
self.assertEquals(obj.method_x(), expectation)
def test_b(self):
obj = Foo.objects.create(a = "baz")
expectation = {"a" : "baz"}
self.assertEquals(obj.method_x(), expectation)
def test_c(self):
obj = Foo.objects.create(a = "bar")
obj2 = Foo.objects.create(a = "baz")
obj.b.add(obj2)
expectation = {"a" : "bar", "b" : {"a": "baz"}}
self.assertEquals(obj.method_x(), expectation)
Run Code Online (Sandbox Code Playgroud)
据我了解,每个测试都是单独运行的,但是当我与测试 a 或 b 一起运行 test_c 时,所有测试都会失败。基本上是这样的: