In this tutorial, you'll learn how to use skip, skipif & xfail Pytests in Python.
—
Facebook: / gokcedbsql
—
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.
I have a confessed.py file and two test files. One for the cash sales report and the other for the customer report. The conf text.py file contains a fixture function read underscore config.
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.
@pytest.mark.skipif(date.today().strftime("%m/%d/%Y") [REMOVED] "03/01/2022", reason="waiting on bug fix")
@pytest.mark.skip
@pytest.mark.xfail
@pytest.mark.second_query
def test_second_query(read_config):
output = read_config.get("query", "cash_sales_report_query2").replace("\"", "")
print("query output: ", output)
assert "SELECT" in output
Смотрите видео How To: Skip, Skipif & Xfail PyTests In Python (2 Min) онлайн, длительностью часов минут секунд в хорошем качестве, которое загружено на канал Gokce DB 26 Март 2022. Делитесь ссылкой на видео в социальных сетях, чтобы ваши подписчики и друзья так же посмотрели это видео. Данный видеоклип посмотрели 418 раз и оно понравилось 7 посетителям.