Giter Club home page Giter Club logo

Comments (8)

AleksandrSulimov avatar AleksandrSulimov commented on June 2, 2024 1

issue resolved in pytest 8.0.0

pytest tests -v -s
platform win32 -- Python 3.10.7, pytest-7.4.4, pluggy-1.4.0 -- 
plugins: base-url-2.1.0, playwright-0.4.4
collected 6 items                                                                                                                                                                     

tests/test_bug.py::test_has_title[chromium-65] PASSED
tests/test_bug.py::test_get_started_link[chromium-65] PASSED
tests/test_bug.py::test_has_title[chromium-90] PASSED
tests/test_bug.py::test_get_started_link[chromium-90] PASSED
tests/test_bug.py::test_has_title[chromium-110] PASSED
tests/test_bug.py::test_get_started_link[chromium-110] PASSED
pytest tests -v -s
platform win32 -- Python 3.10.7, pytest-8.0.0, pluggy-1.4.0 --
plugins: base-url-2.1.0, playwright-0.4.4
collected 6 items                                                                                                                                                                    

tests/test_bug.py::test_has_title[chromium-65] PASSED
tests/test_bug.py::test_has_title[chromium-90] PASSED
tests/test_bug.py::test_has_title[chromium-110] PASSED
tests/test_bug.py::test_get_started_link[chromium-65] PASSED
tests/test_bug.py::test_get_started_link[chromium-90] PASSED
tests/test_bug.py::test_get_started_link[chromium-110] PASSED
import re

import pytest
from playwright.sync_api import Page, expect


@pytest.mark.parametrize("fov_value", ['65', '90', '110'])
def test_has_title(page: Page, fov_value):
    page.goto("https://playwright.dev/")
    expect(page).to_have_title(re.compile("Playwright"))


@pytest.mark.parametrize("fov_value", ['65', '90', '110'])
def test_get_started_link(page: Page, fov_value):
    page.goto("https://playwright.dev/")
    page.get_by_role("link", name="Get started").click()
    expect(page.get_by_role("heading", name="Installation")).to_be_visible()

from playwright-pytest.

crazy-yuzhao avatar crazy-yuzhao commented on June 2, 2024

import pytest
from playwright.sync_api import Page, expect

@pytest.mark.parametrize("x", ["aaa", "bbb"])
def test_a(x, page: Page):
page.goto("https://www.baidu.com")
page.locator("#kw").fill(x)
page.locator("#su").click()
print(page.title())

@pytest.mark.parametrize("y", ["mmm", "nnn"])
def test_b(y, page: Page):
page.goto("https://www.baidu.com")
page.locator("#kw").fill(y)
page.locator("#su").click()
print(page.title())

###########

collecting ... collected 4 items

aaa.py::test_a[chromium-aaa]
aaa.py::test_b[chromium-mmm]
aaa.py::test_a[chromium-bbb]
aaa.py::test_b[chromium-nnn]

from playwright-pytest.

crazy-yuzhao avatar crazy-yuzhao commented on June 2, 2024

import pytest

@pytest.mark.parametrize("x", ["aaa", "bbb"])
def test_a(x):
print(f'{x}')

@pytest.mark.parametrize("y", ["mmm", "nnn"])
def test_b(y):
print(f'{y}')

########
collecting ... collected 4 items

aaa.py::test_a[aaa] aaa
PASSED
aaa.py::test_a[bbb] bbb
PASSED
aaa.py::test_b[mmm] mmm
PASSED
aaa.py::test_b[nnn] nnn
PASSED

from playwright-pytest.

aspenboy avatar aspenboy commented on June 2, 2024

But shouldn't the tests be independent of each other?

from playwright-pytest.

crazy-yuzhao avatar crazy-yuzhao commented on June 2, 2024

But shouldn't the tests be independent of each other?但测试不应该相互独立吗?

It needs to be like the native execution results of pytest. All parameterized test cases need to be executed before other subsequent use cases are executed. You can see the comparison of the results after the two executions above.

from playwright-pytest.

siddiquiakram84 avatar siddiquiakram84 commented on June 2, 2024

Using pytest-playwright, after parameterization, the execution order of use cases is inconsistent with pytest itself.this is bug!!

If you're experiencing inconsistent execution order of test cases in pytest-playwright after parameterization, it's important to note that the order of test execution in pytest is not guaranteed to be consistent. pytest executes test functions in a random order by default to ensure that tests are independent of each other.

However, if the order of execution is critical for your test cases, you can take the following approaches:

Sort the Test Cases Explicitly:

Sort your test cases explicitly within the test file. You can use the pytest.mark.run marker to assign a specific order to your test cases.

import pytest

@pytest.mark.run(order=1)
def test_case1():
# Your test implementation

@pytest.mark.run(order=2)
def test_case2():
# Your test implementation

from playwright-pytest.

symonk avatar symonk commented on June 2, 2024

relates to #204

from playwright-pytest.

mxschmitt avatar mxschmitt commented on June 2, 2024

Great discovery, thanks! Closing by that:

Pytest 7.4.4:

PASSED test_foo.py::test_a[chromium-aaa]
PASSED test_foo.py::test_b[chromium-mmm]
PASSED test_foo.py::test_a[chromium-bbb]
PASSED test_foo.py::test_b[chromium-nnn]

Pytest v8

PASSED test_foo.py::test_a[chromium-aaa]
PASSED test_foo.py::test_a[chromium-bbb]
PASSED test_foo.py::test_b[chromium-mmm]
PASSED test_foo.py::test_b[chromium-nnn]

from playwright-pytest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.