[英]My simple python unittest case not running as expected
Created this simple unit test as shown bellow 创建了这个简单的单元测试,如下所示
calculator_tester.py Calculator_tester.py
import unittest
class MathsTest(unittest.TestCase):
def test_createOperation(self):
operation = Mathoperation()
This is the only test file I have created and Note there doesnot exist a class call Mathoperation() that is defined inside the test method. 这是我创建的唯一测试文件, 请注意 ,在测试方法内部没有定义名为Mathoperation()的类 。 n When running this sample test code using the python test runner
n使用python测试运行器运行此示例测试代码时
python -m unittest
output: 输出:
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
Expectation: 期望:
I was expecting the test case to run and throw NameError: global name Mathoperation is not defined.
我期望测试用例运行并抛出NameError:全局名称Mathoperation未定义。 But the test case didn't run.
但是测试用例没有运行。
What is the sample test case not running. 什么是示例测试用例未运行。 I am running it on python version 2.7.12
我在python版本2.7.12上运行它
Test discovery looks for files matching the glob pattern test*.py
by default. 默认情况下, 测试发现将查找与glob模式
test*.py
相匹配的文件。 Your test doesn't match that pattern. 您的测试与该模式不匹配。 Rename it, or specify the test file explicitly.
重命名它,或明确指定测试文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.