Home > other >  Unit testing error, a great god for help
Unit testing error, a great god for help

Time:11-03

This is to test your code

Def mySum (x, y) :
Return x + y

Def mySub (x, y) :
Return x-y

Print (mySum (1, 1))



This is to test the code
The import unittest
The from danyuanceshi import mySum
The from danyuanceshi import mySub

The class Test (unittest. TestCase) :
Def setUp (self) :
Invoked automatically print (" start ")
Def tearDown (self) :
Print (" at the end of the automatic call ")

Def test_mySum (self) :
Self. AssertEqual (mySum (1, 2), 3, "addition is wrong")
Def test_mySub (self) :
Self. AssertEqual (mySub (2, 1), 1, "subtraction is wrong")
If __name__=="__main__" :
Unittest. The main ()



Below is the error
Testing started at "...
Traceback (the most recent call last) :
The File "F: \ Pyharm5.0.3 \ PyCharm 5.0.3 \ helpers \ PyCharm \ pytestrunner py", line 60, in & lt; module>
The main ()
The File "F: \ Pyharm5.0.3 \ PyCharm 5.0.3 \ helpers \ PyCharm \ pytestrunner py", 34, the line in the main
Pluginmanager=_pluginmanager, args=args)
The File "F: \ python3.7 \ lib \ site - packages \ pluggy \ hooks py", line 286, in __call__
Return the self. _hookexec (self, self. Get_hookimpls (), kwargs)
The File "F: \ python3.7 \ lib \ site - packages \ pluggy \ manager py", line 92, in _hookexec
Return the self. _inner_hookexec (hook, the methods, kwargs)
The File "F: \ python3.7 \ lib \ site - packages \ pluggy \ manager py", line 86, in & lt; Lambda>
Firstresult=hook. Spec. Opts. Get (" firstresult ") if the hooks. The spec else False,
The File "F: \ python3.7 \ lib \ site - packages \ pluggy \ callers py", line 203, in _multicall
Gen. Send (outcome)
The File "F: \ python3.7 \ lib \ site - packages \ _pytest \ helpconfig py", line 89, in pytest_cmdline_parse
The config=outcome. Get_result ()
The File "F: \ python3.7 \ lib \ site - packages \ pluggy \ callers py", line 80, in get_result
Raise the ex [1]. With_traceback (ex [2])
The File "F: \ python3.7 \ lib \ site - packages \ pluggy \ callers py", line 187, in _multicall
Res=hook_impl. Function (* args)
The File "F: \ python3.7 \ lib \ site - packages \ _pytest \ config \ set py", line 736, in pytest_cmdline_parse
The self. The parse (args)
The File "F: \ python3.7 \ lib \ site - packages \ _pytest \ config \ set py", line 939, in the parse
Assert the self. Invocation_params. Args==args
AssertionError


The left side of the above errors also write: unable to attach test report to test framework, or the test framework exit

  • Related