hey guys welcome to the next blog on Python unit testing tutorial for beginners using PI test now in this blog I'm going to show you how you can run your tests which you have written using PI test inside your PyCharm ide so till now we have been running our tests which we have written using pi test on the command prompt or the terminal but using pycharm ide also we can run these tests inside the PyCharm ide so let's see how we can run those tests which we have written using pi test using the PI charm ide so as you can see here on the left hand side i have a class and on the right hand side i have written some tests which are related to this class now i want to run these tests which i have written here using the pi test inside the pycharm ide so for doing this what I need to do is first of all I need to install PI test package inside the pycharm ide so you can see here when I try to import PI test inside the pycharm ide first of all it will give me this red squiggly line which means that PI charm is not recognizing this pi test package till now so let's first of all install this package so just click on file and then click on settings and then go to the section which says project and then your project names so project colon project name so I'm going to click on this and then go to the project interpreter now as you can see here there are some packages which are already here and we want to install a new package which is PI test so I'm going to click on this install or this plus icon here and then I will just search for PI test and the first option you will see here is PI test and you can see this will be the version which will be installed on our PyCharm IDE so what I'm going to do is I'm going to just click on this button let me just move it a little bit above so you can see this button so I'm going to click on this install package button which is going to install PI test package inside my PyCharm ide and once this pi test package is installed you will see this message which says package pi test installed successfully with the green highlighted text that means PI test is installed so you can close this window so I'm going to close this window and you will be able to see this pi test now is added to your project interpreter so now when I click on ok and I will wait for some time till this process has been finished and then after some time you will see this red squiggly line under this pi test is gone so now our pycharm ide recognizes this pi test package and now we want to tell the pi CIAM ide that we want to run the PI tests so for doing that once again I will click on file and then go to the settings and then this time I will go to that tools so just click on Tools option and when you scroll down you will be able to see this option which says python integrated tools so just click on this and on the right hand side you will be able to see under testing that default test runner by default is unit tests so we need to change this to PI test ok so just change this default test Runner to PI test and then apply and then click OK which is going to tell pycharm IDE that we want to run the PI tests now as soon as you are finished with the setting of PI test on your pycharm IDE what you can do now is you can right click on the file where you want to run PI tests so this is my test underscore math underscore func dot py file where all my tests are there so just right click on this file and then you will be able to see this option which says run PI test in the file you want to run the PI test so just click on this option which says run PI test in the file and as soon as you do this you will be able to see this window which is for the PI test and you will be able to see all the tests which have been passed on the left-hand side and the terminal output on the right-hand side so let me just maximize this window here and on the right hand side you will be able to see the output so we have run the test on this file and because I have some output which is a print output as you can see here print statement here which is responsible for printing this line and also I have this print statement for teardown so this teardown is printed using this print statement also you will be able to see two dots here which means we have a two tests inside this file which ran successfully so let's add this verbose flag inside our PI tests using pycharm ide so once you ran your PI test using PyCharm ide you will be able to see this drop down menu here it says PI test in whatever file you are running your PI test on and just click on this file you will be able to see this added configuration option right away after first run of your test so just click on this option which says added configuration and then you can add the arguments which are additional arguments like verbose or - s or whatever option you want to provide here using this additional arguments option so let's say I want to provide this - V option which is for verbose and then I will say apply and then I will say ok and then I'm going to run that test once again either clicking on this button or right away from this button so let me click on this button and once you ran your test you will be able to see the verbose output on the right hand side let me just remove these print statements because they are just not looking good on the tests so I'm going to just remove the setup and teardown pretty print statements from here and I'm going to run the tests once again and then you will be able to see the correct verbose output here now if you want to see all these tests which are passed or failed on the left-hand side using these green or red circles then you can click on this green circle at the top here so once click on this green circle and you will be able to see the list of all tests which are there inside your file so this is the script name which is test underscore math underscore func and these are the two tests which are there inside this test script so you can see the first test is test core data which is this one and the second test is test mark data which is the second test here you can also run these tests individually so you can right click and then you can just say run test which is going to run only one test which you want to run so once you ran this only one test you will be able to see on the top that only this tests has been running so in order to run the whole Python script for the test you can once again select this option which is PI test in whatever test script you have so we'll just choose that and then run it once again it will run your all the tests once again and you will be able to see all the tests here so in order to run individual tests you can just right click and then run those tests but remember that you need to change this option again from here also if you want to run the test by just hovering over the test so this is the test let's say I want to run only this test so you can just hover over this test and then right click and then just click on this option run by test for this test which is going to run only that test once again I'm going to select this option for the whole file which is going to run all the tests once again for the PI test using PyCharm ide so this is how you can run your tests which you have written using pi tests using PyCharm ide I hope you've enjoyed this blog and I will see you in the next blog
Post a Comment