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

Veröffentlicht am: 20 März 2022
auf dem Kanal: Gokce DB
358
6

In this tutorial, you'll learn how to write a PyTest unit test in Python using PyCharm with examples.

—
Facebook:   / gokcedbsql  
—
Video Transcript:
—
Connect MySQL In Python:    • How To Connect To MySQL In Python (2 ...  
—
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.

from src.report.report import Report

def test_get_first_query():
rep = Report("cash_sales")
print("first query:", rep.get_first_query())
assert "SELECT" in rep.get_first_query()

def test_get_second_query():
rep = Report("cash_sales")
print("second query:", rep.get_second_query())
assert "XYZ" in rep.get_second_query()


Auf dieser Seite können Sie das Online-Video How To: Write a PyTest In Python Using PyCharm (2 Min) | Unit Test Example mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Gokce DB 20 März 2022 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 358 Mal angesehen und es wurde von 6 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!