如何强制 Pycharm 运行所有单元测试? [英] How to force Pycharm to run all unit tests?

查看:75
本文介绍了如何强制 Pycharm 运行所有单元测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个单元测试文件,我可以在 Pycharm 中运行测试.美好的.但是,Pycharm 似乎会根据一些有关代码更改的标准跳过测试.例如,如果测试方法中的代码没有改变,和/或特定测试方法测试的代码没有改变,它就不会运行测试.这造成了很多痛苦,并且让一个直到很久以后才被发现的错误落了下来.所以我的问题是,如何阻止 Pycharm 自动跳过测试并强制它运行所有测试?

I have a single unit test file, and I can run tests within Pycharm. Fine. However, it seems that Pycharm skips tests based on some criteria regarding code change. Something like, if the code in a test method hasn't changed, and/or if the code that a particular test method is testing hasn't changed, it won't run the test. This has caused a lot of pain, and has let a bug fall through that wasn't caught until much later on. So my question is, how to stop Pycharm from automatically skipping tests and force it to run all tests?

为什么跳过测试是默认行为?这对我来说似乎非常离谱,但如果我错了,请纠正我.

Why is skipping tests the default behaviour anyway? This seems absolutely outrageous to me, but please correct me if I'm wrong.

编辑哎呀我的坏.我通过在 Mac OS 上按键盘快捷键 control-shift-R 来运行测试,它通常运行一个 Python 脚本,但它实际上并没有运行整个测试文件,而只运行一个测试(插入符号所在的位置)反而.这(具有不同行为的键盘快捷键)在我看来有点误导,但无论如何,我对问题的描述是错误的,我错了.对不起!

EDIT Oops my bad. I ran the tests by pressing the keyboard shortcut control-shift-R on my Mac OS, which normally runs a Python script, but it doesn't actually run the whole test file, and only runs a single test (where the caret is) instead. This (keyboard shortcut having different behaviours) is a little bit misleading in my opinion, but regardless, my description of the problem is wrong and I was wrong. Sorry!

推荐答案

确保所有测试方法都以 test_ 开头.

Make sure all your test methods staring with a test_.

通常我有 2 个测试配置:全部当前.

Usually I have 2 Tests configurations: All and Current.

tests 文件夹位于 PyCharm 项目的根目录

tests folder is located in the root of PyCharm project

我使用 python 路径来指定要运行的某些测试.您可以轻松地将参考复制到某个测试

I use python path to specify certain test to run. You can easily copy the reference to certain test

这篇关于如何强制 Pycharm 运行所有单元测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆