Search code examples
pythonpytestplaywright

Skipping playwright test gives pytest is not defined


I can run my python playwright tests ok

However I want to skip one

I added @pytest.mark.skip but I get the error 'pytest' is not defined

import re
from playwright.sync_api import Page, expect

    def test_has_title(page: Page):
        page.goto("https://bbc.com")
    
        # Expect a title "to contain" a substring.
        expect(page).to_have_title(re.compile("BBC Home"))
    
    @pytest.mark.skip('skip')
    def test_get_started_link(page: Page):
        page.goto("https://bbc.com")
    
        # Click the get started link.
        page.get_by_role("link", name="Home").click()
    
        # Expects page to have a heading with the name of Installation.
        expect(page.get_by_role("heading", name="BBC")).to_be_visible()

.......

==================================== ERRORS =====================================
_________________________ ERROR collecting test_bbc.py __________________________
test_bbc.py:10: in <module>
    @pytest.mark.skip('skip')
E   NameError: name 'pytest' is not defined
============================ short test summary info ============================
ERROR test_bbc.py - NameError: name 'pytest' is not defined
!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!
=============================== 1 error in 0.03s ================================

Solution

  • You want to add:

    import pytest