pytest

   1 mkdir test-pytest
   2 cd test-pytest/
   3 python3 -m venv testVenv
   4 source testVenv/bin/activate
   5 nano unitTest.py 
   6 nano requirements.txt
   7 pip install -r requirements.txt 
   8 pytest unitTest.py 

requirements.txt

pytest

unitTest.py

   1 import unittest
   2 
   3 class SimpleTestCase(unittest.TestCase):
   4     def setUp(self):
   5         self.res=4
   6 
   7     def tearDown(self):
   8         self.res=0
   9 
  10     def testAdd1(self):
  11         res=2+2
  12         self.assertEqual(self.res,res,'')       
  13 
  14     def testAdd2(self):
  15         res=2+3
  16         self.assertEqual(self.res,res,'')       
  17 
  18     def testAdd3(self):
  19         res=2+3
  20         self.assertNotEqual(self.res,res,'')

Python/pytest (last edited 2021-08-03 21:04:53 by localhost)