filmov
tv
How To: Skip, Skipif & Xfail PyTests In Python (2 Min)

Показать описание
In this tutorial, you'll learn how to use skip, skipif & xfail Pytests in Python.
—
—
Video Transcript:
—
Hi guys, this is Abhi from Gokcedb. In this video, you're going to learn the skip skipif and xfill markers in the PI test. Let's start by looking at the tests directory.
The cache underscore sales test file contains two test functions whereas the customer file contains only one test function. If I execute all the tests in the test directory, I see that one test failed and the other two passed. The reason this test failed is that the XYZ keyword doesn't appear in the query output.
Say I want this failing test to be ignored. To do that I'll use the at PI tesT dot mark dot skip decorator. Now if I re-execute all the tests you will see that this test was ignored and marked as skipped.
You can also see the ignored status in the exported test results. Next, say I only want to ignore this test until April 1st, 2022 because I'm waiting on a bug fix. To do that I'll use the skip if marker.
Now when I re-run the tests, this test will be skipped for the reason of waiting on a bug fix in the test logs. If I change the date to March 1st, 2022 which is in the past the skip condition will fail which means the test will no longer be ignored. Finally, let's look at the 1 fail marker.
You use the x-fail marker when you're expecting the test to fail. With x fail the test still gets executed. However, in the summary starts it gets marked as ignored.
We can confirm this by looking at the HTML output as well. However, if the failing test passes then the pass status will propagate to the summary stats as well. There you have it.
Make sure you like, subscribe, and turn on the notification bell. Until next time.
def test_second_query(read_config):
print("query output: ", output)
assert "SELECT" in output
—
—
Video Transcript:
—
Hi guys, this is Abhi from Gokcedb. In this video, you're going to learn the skip skipif and xfill markers in the PI test. Let's start by looking at the tests directory.
The cache underscore sales test file contains two test functions whereas the customer file contains only one test function. If I execute all the tests in the test directory, I see that one test failed and the other two passed. The reason this test failed is that the XYZ keyword doesn't appear in the query output.
Say I want this failing test to be ignored. To do that I'll use the at PI tesT dot mark dot skip decorator. Now if I re-execute all the tests you will see that this test was ignored and marked as skipped.
You can also see the ignored status in the exported test results. Next, say I only want to ignore this test until April 1st, 2022 because I'm waiting on a bug fix. To do that I'll use the skip if marker.
Now when I re-run the tests, this test will be skipped for the reason of waiting on a bug fix in the test logs. If I change the date to March 1st, 2022 which is in the past the skip condition will fail which means the test will no longer be ignored. Finally, let's look at the 1 fail marker.
You use the x-fail marker when you're expecting the test to fail. With x fail the test still gets executed. However, in the summary starts it gets marked as ignored.
We can confirm this by looking at the HTML output as well. However, if the failing test passes then the pass status will propagate to the summary stats as well. There you have it.
Make sure you like, subscribe, and turn on the notification bell. Until next time.
def test_second_query(read_config):
print("query output: ", output)
assert "SELECT" in output