Skip a test in Pytest

In this blog, we are working on how to skip the test cases in the Pytest file. 


As a pre-requisite we have to check whether the following dependencies are installed or not:

  1. Project setup. 
  2. Run pip list in PyCharm terminal to check whether playwright is installed or not. 

As shown in the above picture playwright should be installed in the project. 

If the playwright is not installed refer to Web Automation Testing using Playwright.

Playwright supports the Pytest Framework. We can use the same Pytest command for both Sync and Async APIs. 


To install Pytest we have to run the following command in the terminal. 

pip install pytest-playwright 

After the successful installation of Pytest run pip list in terminal to check whether the Pytest is installed successfully or not.  

If Pytest is not installed then check out the blog on How to run the single test case in Pytest

In Playwright we can skip the test by using the Built-In marker of Pytest I.e skip. 

A) Skip:

The simplest way to skip a test function is to mark it with the skip decorator and optionally pass the reason as a parameter. 

Test Case:

In the above code snippet, in the statement at line no. 12 we have marked the test function with decorator as @pytest.mark.skip. 

As you can see in the above terminal output the Pytest has skipped the test function with reason, which is marked by the skip decorator. 

B) Skip whole test script:

  1. We can skip the whole test Script or test case file by providing the name of the test case file as xtest_ 
  2. Xtest will not consider the test case file for execution. 


Pytest engine will auto-check the file name and if the file name is encountered as xtest then it will skip the whole test case file. As shown in the above example the test script file named as will be skipped by the Pytest engine. 

Read the next Playwright blog Here.