首页 文章

Py.test失败,但./manage.py测试工作正常

提问于
浏览
1

我最近接管了一个代码库,然后我开始添加Selenium测试并转移到py.test . 我喜欢py.test由于并行性和其他第三方包,但我注意到py.test的主要问题 .

代码库是Django堆栈(Python 2.7上的1.8,pytest-2.6.4,目前没有x-dist) .

1)py.test测试比正常的django测试套件运行得慢(不是很好,但我可以忍受)

2)当我通过执行 py.testsome of the unittest fail 与Selenium测试一起运行unittests时 . 如果我只使用py.test运行unittest(使用 @skipUnless decorator排除), everything passes fine . 当我使用 ./manage.py test 运行(unittest&selenium)时,所有测试都运行良好 .

py.tests失败(在使用unittest和selenium的运行中)有一个奇怪的错误 DoesNotExist: ActionType matching query does not exist. .

Is py.test running tests differently than the normal Django test suite?

Any suggestions why the unittest fail when I run it together with the Selenium tests?

Selenium测试在失败的单元测试之前执行,但它们遇到了代码的不同区域(不同的模块) .

1 回答

  • 0

    我刚刚修了一个类似的案子 . 问题是查询无法返回我期望存在的对象 .

    事实证明它们应该由信号处理程序创建 . 这些处理程序是在import.py之类的导入时注册的

    @receiver(post_save, sender=CustomUser)                                         
    def create_email_verification(sender, instance, created, **kwargs):
    

    signals.py是从相应模块的App configs导入的 .

    原来,app配置从未加载(由于缺少 default_app_config ),但Django无论如何都加载了signals.py . 但是当通过py.test运行时,模块没有加载(因为它没有在其他任何地方导入),因此信号处理程序从未注册过 .

    结论: manage.py test 似乎是自动导入一些模块,py.test没有 . 可能有一些代码(信号处理程序)未明确导入 .

相关问题