【发布时间】:2018-01-24 23:35:37
【问题描述】:
我有一个非常简单的类,它在任何版本的 pytest>3.0.0 上都失败了。当我使用--pdb 调用测试时。
from django.test import TestCase
class TestTestCase(TestCase):
"""Tests for the TestCase class."""
def test_that_client_exists(self):
"""Assert that the class has a client."""
assert self.client
我正在使用以下版本:
- 平台 Linux
- Python 2.7.11
- pytest-3.3.1
- py-1.5.2
- pluggy-0.6.0
- django-2.9.2
我收到以下错误:
self = <myproject.tests.test_test_case.TestTestCase testMethod=test_that_client_exists>
def test_that_client_exists(self):
"""Assert that the class has a client."""
> assert self.client
E AttributeError: 'TestTestCase' object has no attribute 'client'
但是,如果我降级到 pytest==3.0.0 和 pluggy-0.3.1,代码将毫无问题地执行。我的问题是,这是怎么回事?这可能是什么原因造成的?
好像 pytest 正在调用 test_that_client_exists,但没有调用 __call__,后者调用了 _pre_setup。
有人见过这样的吗?
【问题讨论】:
-
测试使用干净的 django 项目(Python 2.7.10、
django==1.11.9、pytest==3.3.2、pytest-django==3.1.2)运行。那里一定有别的东西。 -
所以如果我从测试调用中删除
--pdb,这个问题就会消失。
标签: django pytest pdb pytest-django