X-Received: by 2002:a37:8704:: with SMTP id j4-v6mr5925622qkd.9.1535627541127; Thu, 30 Aug 2018 04:12:21 -0700 (PDT) X-Received: by 2002:ac8:7255:: with SMTP id l21-v6mr115812qtp.1.1535627540852; Thu, 30 Aug 2018 04:12:20 -0700 (PDT) Path: csiph.com!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!z10-v6no908140qtb.0!news-out.google.com!k67-v6ni530qte.1!nntp.google.com!z10-v6no908136qtb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: de.comp.lang.python Date: Thu, 30 Aug 2018 04:12:20 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=78.35.13.203; posting-account=cCztUgoAAAD5_0KiXUWZldZlMvvFrFk6 NNTP-Posting-Host: 78.35.13.203 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: From Unittest (lib) to pytest without problems? From: frentmeister Injection-Date: Thu, 30 Aug 2018 11:12:21 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Lines: 195 Xref: csiph.com de.comp.lang.python:5222 **Task** I have to change some of my tests from unittest (library) to Pytest, unfort= unately 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 n= ot get on. My setup refers to test cases that test switch functionalities on a CLI bas= is. 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 t= ext 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 compone= nts (see above)? 7. Where are there good examples of Pytest and Router / Switch Test? How pr= oblematic 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 t= est? How do I implement an existing testuit in Pytest? **setup:**=20 Python 3.7, Unittest =20 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 =3D testcore.control.ssh.SSH(host=3D'xxx.xx.xxx.250', userna= me=3D'admin', password=3D'admin') self.s.query_interactive =3D True =20 First Test on the Switch def test_change_Enforce_Enable(self): if self.s.login(): q =3D self.s.query('account') # switch to prompt account q =3D self.s.query('enforce-Password-Rules yes') Here i start the Testsuit =20 # intial test # class Test_User(unittest.TestCase): =20 def test_create_user(self): # self-filfilling assert 1 if self.s.login(): q =3D self.s.query('account') # switch to prompt account q =3D self.s.query('add 10 testuser1 testuser1 ') q =3D self.s.query('add 11 testuser2 testuser2 ') q =3D self.s.query('add 11 testuser3 testuser3 ') q =3D self.s.query('add 11 testuser4 testuser4 ') q =3D self.s.query('add 11 testuser5 testuser5 ') q =3D self.s.query('add 11 testuser6 testuser6 ') q =3D self.s.query('add 11 testuser7 testuser7 ') q =3D self.s.query('add 11 testuser8 testuser8 ') q =3D self.s.query('add 11 testuser9 testuser9 ') q =3D self.s.query('add 11 testuser10 testuser10 ') import time print('Wait') time.sleep(3) # create testadmins privileg 15 q =3D self.s.query('add 15 testadmin1 testadmin1 ') q =3D self.s.query('add 15 testadmin2 testadmin2 ') q =3D self.s.query('add 15 testadmin3 testadmin3 ') q =3D self.s.query('add 15 testadmin4 testadmin4 ') q =3D self.s.query('add 15 testadmin5 testadmin5 ') import time print('Wait') time.sleep(3) # more testadmins q =3D self.s.query('add 15 testadmin1 testadmin6 ') q =3D self.s.query('add 15 testadmin2 testadmin7 ') q =3D self.s.query('add 15 testadmin3 testadmin8 ') q =3D self.s.query('add 15 testadmin4 testadmin9 ') q =3D self.s.query('add 15 testadmin1 testadmin11 ') q =3D self.s.query('add 15 testadmin2 testadmin12 ') q =3D self.s.query('add 15 testadmin3 testadmin13 ') q =3D self.s.query('add 15 testadmin4 testadmin14 ') q =3D self.s.query('add 15 testadmin5 testadmin15 ') import time print('Wait') time.sleep(10) def test_delete_user(self): if self.s.login(): q =3D self.s.query('account') q =3D self.s.query('delete testuser1 ') q =3D self.s.query('delete testuser2 ') q =3D self.s.query('delete testuser3 ') q =3D self.s.query('delete testuser4 ') q =3D self.s.query('delete testuser5 ') q =3D self.s.query('delete testuser6 ') q =3D self.s.query('delete testuser7 ') q =3D self.s.query('delete testuser8 ') q =3D self.s.query('delete testuser9 ') q =3D self.s.query('delete testuser10 ') import time print('Wait') time.sleep(10) # create testadmins privileg 15 q =3D self.s.query('delete testadmin1 ') q =3D self.s.query('delete testadmin2 ') q =3D self.s.query('delete testadmin3 ') q =3D self.s.query('delete testadmin4 ') q =3D self.s.query('delete testadmin5 ') import time print('Wait') time.sleep(10) # def test_user_password(self): # if self.s.login(): # q =3D self.s.query('add 15 =C3=9F =C3=9F') # import time # print('Wait') # time.sleep(3) # print('it=C2=B4s not possible ') def test_creat_user_nopassword(self): if self.s.login(): q =3D self.s.query('add 15 Testusernopassword ') import time print('Wait') time.sleep(3) print('it=C2=B4s not possible to create a user admin') def test_creat_admin(self): if self.s.login(): q =3D self.s.query('add 15 admin admin') print('it=C2=B4s not possible to create a user admin') import time print('Wait') time.sleep(3) def test_split(self): # code here pass =20 def tearDown(self): # your code to clean or close the connection pass =20 =20 if __name__ =3D=3D '__main__': unittest.main(verbosity=3D3) unittest.main(warnings=3D'ignore') log_file =3D 'log_file.txt' f =3D open(log_file, "w") runner =3D unittest.TextTestRunner() runner.run(suite())