How To: Write a PyTest In Python Using PyCharm (2 Min) | Unit Test Example

preview_player
Показать описание
In this tutorial, you'll learn how to write a PyTest unit test in Python using PyCharm with examples.



Video Transcript:


Hi guys, this is Abhi from Gokcedb. In this video, you're going to learn how to create a test in Python using PI test and Pycham. Let's start by clicking on the Python packages tab and ensuring that the PI test package is installed.

Next right click on the root project folder and select the Python package from the new dropdown. Write for the new Python packages and then hit enter. Now say I want you to write a test to get the first query method in the report class.

To do that right click on the get first query method and select test from the go-to dropdown. Click on create new test then hit ok. Now I can import the report class in my test file and then create a new report object.

Next, let's print the output of the get first query method. Now we can assert whether the get first query output contains the keyword select or not. To execute this test, right-click on the name of the test and then choose the run PI test.

Looks like our test passed. Let's add one more test to test the get second query method. This time I want the test to fail so I will assert whether the get second query output contains the keyword XYZ or not.

Right-click on the name of the test file then hit run to execute. To export, the test result clicks on the export test results button. I'm going to choose HMTL for the format and then hit ok.

Now you should be able to look at your test result in a browser. There you have it. Make sure you like, subscribe, and turn on the notification bell.

Until next time.

def test_get_first_query():
rep = Report("cash_sales")

def test_get_second_query():
rep = Report("cash_sales")
Рекомендации по теме
Комментарии
Автор

I love programing and I wanted to be in one, I hope I am the winner for the giveaway so that i can follow every step and be the best in what I love
thank you for the thoughtfulness brother hug respect!!!

rzuhmww