Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > de.comp.lang.python > #5222

From Unittest (lib) to pytest without problems?

Newsgroups de.comp.lang.python
Date 2018-08-30 04:12 -0700
Message-ID <a017894e-a38a-4e0a-a663-fe4d6957a791@googlegroups.com> (permalink)
Subject From Unittest (lib) to pytest without problems?
From frentmeister <frank.rentmeister@gmail.com>

Show all headers | View raw


**Task**

I have to change some of my tests from unittest (library) to Pytest, unfortunately I have to do with my scope of test I'm here to consider that I can not take over all the function so. With a research to come and I just can not get on.

My setup refers to test cases that test switch functionalities on a CLI basis.

 1. Log on to the switch with SSH and Pyserial
 2. Running querys on the prompt environment
 3. After completion of the test, the test process should be written in a text file

**Ask:**

5. Can I use the source I currently use so synonymous with Pytest?
6. What do I have to rebuild so that I can continue to use the core components (see above)?
7. Where are there good examples of Pytest and Router / Switch Test? How problematic is a comprehensive remodeling of several 1000 test cases?
8. A very important point would also be that I have a test suite in other test? How do I implement an existing testuit in Pytest?


**setup:** 

Python 3.7, Unittest

   
    import unittest
    from test import support
    import paramiko


Here i use this class

    class SwitchAccount(unittest.TestCase):  # This class inherits unittest.TestCase

The connection to the switch

    def setUp(self):
        self.s = testcore.control.ssh.SSH(host='xxx.xx.xxx.250', username='admin', password='admin')

        self.s.query_interactive = True

        
First Test on the Switch

    def test_change_Enforce_Enable(self):

        if self.s.login():
            q = self.s.query('account')

            # switch to prompt account

            q = self.s.query('enforce-Password-Rules yes')

Here i start the Testsuit        

        # intial test
        # class Test_User(unittest.TestCase):

        

    def test_create_user(self):

        # self-filfilling
        assert 1

        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)

            # create testadmins privileg 15

            q = self.s.query('add 15 testadmin1 testadmin1 ')
            q = self.s.query('add 15 testadmin2 testadmin2 ')
            q = self.s.query('add 15 testadmin3 testadmin3 ')
            q = self.s.query('add 15 testadmin4 testadmin4 ')
            q = self.s.query('add 15 testadmin5 testadmin5 ')
            import time
            print('Wait')
            time.sleep(3)

            # more testadmins

            q = self.s.query('add 15 testadmin1 testadmin6 ')
            q = self.s.query('add 15 testadmin2 testadmin7 ')
            q = self.s.query('add 15 testadmin3 testadmin8 ')
            q = self.s.query('add 15 testadmin4 testadmin9 ')
            q = self.s.query('add 15 testadmin1 testadmin11 ')
            q = self.s.query('add 15 testadmin2 testadmin12 ')
            q = self.s.query('add 15 testadmin3 testadmin13 ')
            q = self.s.query('add 15 testadmin4 testadmin14 ')
            q = self.s.query('add 15 testadmin5 testadmin15 ')
            import time
            print('Wait')
            time.sleep(10)

    def test_delete_user(self):

        if self.s.login():
            q = self.s.query('account')
            q = self.s.query('delete testuser1 ')
            q = self.s.query('delete testuser2 ')
            q = self.s.query('delete testuser3 ')
            q = self.s.query('delete testuser4 ')
            q = self.s.query('delete testuser5 ')
            q = self.s.query('delete testuser6 ')
            q = self.s.query('delete testuser7 ')
            q = self.s.query('delete testuser8 ')
            q = self.s.query('delete testuser9 ')
            q = self.s.query('delete testuser10 ')
            import time
            print('Wait')
            time.sleep(10)

            # create testadmins privileg 15

            q = self.s.query('delete testadmin1 ')
            q = self.s.query('delete testadmin2 ')
            q = self.s.query('delete testadmin3 ')
            q = self.s.query('delete testadmin4 ')
            q = self.s.query('delete testadmin5 ')
            import time
            print('Wait')
            time.sleep(10)


        # def test_user_password(self):

        # if self.s.login():

        # q = self.s.query('add 15 ß ß')
        # import time
        # print('Wait')
        # time.sleep(3)
        # print('it´s not possible ')


    def test_creat_user_nopassword(self):

        if self.s.login():
            q = self.s.query('add 15 Testusernopassword ')
            import time
            print('Wait')
            time.sleep(3)
            print('it´s not possible to create a user admin')


    def test_creat_admin(self):

        if self.s.login():
            q = self.s.query('add 15 admin admin')
            print('it´s not possible to create a user admin')
            import time
            print('Wait')
            time.sleep(3)


    def test_split(self):
        # code here
        pass
    
    def tearDown(self):
        # your code to clean or close the connection
        pass
    
    
    if __name__ == '__main__':
        unittest.main(verbosity=3)
        unittest.main(warnings='ignore')
        log_file = 'log_file.txt'
        f = open(log_file, "w")
        runner = unittest.TextTestRunner()
        runner.run(suite())

Back to de.comp.lang.python | Previous | Next | Find similar


Thread

From Unittest (lib) to pytest without problems? frentmeister <frank.rentmeister@gmail.com> - 2018-08-30 04:12 -0700

csiph-web