Home > other >  Unittest assertion failure after the console print "assertion failure" problem
Unittest assertion failure after the console print "assertion failure" problem

Time:11-28

My code:
 
The import unittest
Import from DDT DDT, data


@ DDT
The class TestDdt (unittest. TestCase) :
Def setUp (self) :
Print (" setUp once before each test case execution ")

Def tearDown (self) :
Print (" tearDown after each test case execution is to perform a ")

@ data (1, 2)
Def test_single_element (self value) :
"" "
Test a single set of element
: return:
"" "
Print (value)
Value, self. AssertEqual (1)


If __name__=="__main__ ':
Unittest. The main ()


Results:
 setUp before each test case execution performs a 
1
TearDown after each test case execution is executed a
The setUp before each test case execution performs a
2
TearDown after each test case execution is executed a


1!=2

Expectations:
2Practice: 1

Traceback (the most recent call last) :
The File "F: \ PyCharm \ PyCharm Community Edition 2020.2 \ plugins \ python - ce, helpers, PyCharm \ teamcity \ diff_tools py", line 32, in _patched_equals
Old (self, first, second, MSG)
The File "C: \ Users \ LJX \ AppData \ Local \ designed \ Python \ Python38 \ lib \ unittest \ case py", line 912, in assertEqual
Assertion_func (first, second, MSG=MSG)
The File "C: \ Users \ LJX \ AppData \ Local \ designed \ Python \ Python38 \ lib \ unittest \ case py", line 905, in _baseAssertEqual
Raise the self. FailureException (MSG)
AssertionError: 2!=1

During handling of the above exception, another exception occurred:

Traceback (the most recent call last) :
File "C: \ Users \ LJX \ AppData \ Local \ Python38 \ lib \ \ designed \ Python unittest \ case py", 60, the line in testPartExecutor
Yield
File "C: \ Users \ LJX \ AppData \ Local \ Python38 \ lib \ \ designed \ Python unittest \ case py", line 676, in the run
Self. _callTestMethod (testMethod)
The File "C: \ Users \ LJX \ AppData \ Local \ designed \ Python \ Python38 \ lib \ unittest \ case py", line 633, in _callTestMethod
Method ()
The File "E: \ pythonProject_1 \ venv \ lib \ site - packages \ DDT. Py", line 182, wrapper in
Return func (self, * args, * * kwargs)
The File "E: \ pythonProject_1 \ Excel_operation \ for_ddt py", line 20, in test_single_element
Value, self. AssertEqual (1)



Ran 2 tests in 0.006 s

FAILED (failures=1)

Process is over, exit code 1

Assertion failure

Assertion failure

Assertion failure


Here asserted a success, a failure, but why to print the assertions failed 3 times?
  • Related