Comments (8)
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.
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.
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.
But shouldn't the tests be independent of each other?
from playwright-pytest.
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.
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.
relates to #204
from playwright-pytest.
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)
- Setting locale for a test affects the local for other tests HOT 1
- Coverage support HOT 1
- [BUG] Error when installing in Python 3.12 HOT 2
- Pytest.ini set --screenshot="only-on-failure" --video="retain-on-failure" Screenshots and recorded videos will also be generated after the use case is successfully executed.
- playwright._impl._api_types.Error: net::ERR_CONNECTION_TIMED_OUT at https://www.google.com HOT 2
- [FEATURE] Support connecting to remote browsers HOT 1
- Request: `async` support HOT 4
- [FEATURE] Support pytest 8.x HOT 3
- [BUG]The execution sequence is incorrect when use parametrize HOT 1
- Request: extending `browser_type_launch_args` to work with `request`
- [FEATURE] Support for multiple browser contexts in a single test HOT 1
- [FR] Support for working with pytest-rerunfailures to only create --output on true failure
- Allow extending playwright capabilities HOT 2
- run with --video on --screenshot on how to set screenshot dir and how to get videoname and screenshot name? HOT 1
- pytest-playwirght uses --video="on" to record video,the recorded video only records the newly opened tab page HOT 5
- Move creation of artifacts_folder into a fixture HOT 2
- [BUG]PermissionError: [WinError 5]
- [FEATURE] Implement steps for Trace Viewer HOT 1
- [Feature]: Expose output_dir as a fixture HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from playwright-pytest.