0

Currently I would like to define a test suite for 50 test cases via the Python Test Suite, which is included in Unit test.

Unfortunately, the created class refuses to work properly.

Unittest is involved in the import and works.

import unittest
import test 
import logging
import random

class SwitchTestComplete(unittest.TestSuite):

def setUp(self):


        self.s = SSH(host='xxx.xx.xx.xxx', username='xxxxx', password='xxx')
        self.s.query_interactive = True
    def suite(self):

       suite = unittest.TestSuite()
       suite.addTest(SwitchTestComplete('test_accounting_disable'))
       suite.addTest(test_account_enable('test_account_enable'))
       #suite.addTest(test_accounting_disable('test_create_user'))
       #suite.addTest(test_accounting_disable('test_delete_user'))
       #suite.addTest(test_accounting_disable('test_delete_admin'))
       #suite.addTest(test_accounting_disable('test_create_user_admin'))
       #suite.addTest(test_accounting_disable('test_auto_logout'))
       self.run(suite)

The Test

def test_create_user(self):
            if self.s.login():
              q = self.s.query('account')
              #switch to prompt account
              q = self.s.query('add 10 testuser1 testuser1 ')
              q = self.s.query('add 11 testuser2 testuser2 ')
              q = self.s.query('add 11 testuser3 testuser3 ')
              q = self.s.query('add 11 testuser4 testuser4 ')
              q = self.s.query('add 11 testuser5 testuser5 ')
              q = self.s.query('add 11 testuser6 testuser6 ')
              q = self.s.query('add 11 testuser7 testuser7 ')
              q = self.s.query('add 11 testuser8 testuser8 ')
              q = self.s.query('add 11 testuser9 testuser9 ')
              q = self.s.query('add 11 testuser10 testuser10 ')


              import time
              print('Wait')
              time.sleep(3)

The problem that occurs is that the unit test runs though but does not call the test cases that I have specified here.

glibdud
  • 7,550
  • 4
  • 27
  • 37
  • you seem to mix two things - an actual test and adding it to a suite. also your commented code distracts attention form you problem - care to put out an https://stackoverflow.com/help/mcve instead? – Evgeny Aug 24 '18 at 12:17
  • have a look at https://stackoverflow.com/a/12011486/1758363 - it creates a suite cleanly. pay attention you should not introduce new mocks/setups in suite - merely just assemblee existing tests. – Evgeny Aug 24 '18 at 12:22

1 Answers1

1

In addition to comments above, here is a simple suite example to build upon.

import unittest 

# your intial test
class Test_User(unittest.TestCase):
    def test_create_user(self):
          # self-filfilling
          assert 1

# make a suite
ts = unittest.TestSuite()

# add new instance to a suite
ts.addTest(Test_User('test_create_user'))

# run suite
runner=unittest.TextTestRunner()
runner.run(ts)

Follow-up suggestions:

  • do not make your suite a class, it is an instance
  • do not try to introduce new setups in a suite, rather inherit a testcase with basic setup, I think it is cleaner
  • (very subjective take) use pytest - it is much simplier and faster to develop than traditional unittest library
Evgeny
  • 4,173
  • 2
  • 19
  • 39