10,526 questions
0
votes
1
answer
54
views
Automatically fail all tests that write to stdout or stderr [duplicate]
Using pytest, I can make a single unit test fail if the body of the test wrote anything to stdout or stderr with something like:
import pytest
def test_no_stray_output(capsys: pytest.CaptureFixture[...
Advice
0
votes
0
replies
39
views
Best practices to apply pytest-recording @pytest.mark.vcr to tests in a large test suite?
I am integrating pytest-recording into an existing Python project in order to record HTTP interactions during tests. Pytest-recording is built on vcr.py
pytest-recording uses the @pytest.mark.vcr ...
0
votes
0
answers
25
views
How do I get my tags, on a single Allure 2 test report pane, to show up in alpha-sorted order?
My team is porting to Allure 2 to report our tests. Our pytest tests have a bunch of attributes that I have implemented as allure tags.
In the report page, when I click on a single test on the left ...
Advice
0
votes
0
replies
19
views
Does Python Playwright used with Pytest have the ability to add a global script timeout value?
We have some JavaScript Playwright tests, and they use a configuration that includes a global script 'timeout' value, and you can also set other timeouts in this config. So, in the playwright.config....
Best practices
0
votes
2
replies
38
views
Structuring the project for pytest
I want to group all test files in one directory called tests, but if i nest my tests when I run pytest I get an error because it can't load the function sum, which is inside the module lib, which is ...
2
votes
1
answer
107
views
How do you retry Playwright tests in Python?
There is nice documentation for how to tell Playwright to retry tests using Node.js, but I can't find anything on how to do so with Python/Pytest. The closest solution I can find is pytest-...
1
vote
1
answer
93
views
How to implement SQLAlchemy 2.0 transactions in FastAPI routes while maintaining test isolation with Savepoints?
I'm using FastAPI with SQLAlchemy 2.0 (Async). I want to follow the best practice of wrapping my route logic in transactions. However, I'm struggling to make this work with my Pytest suite where I use ...
0
votes
1
answer
28
views
pytest hooks rewrite on imported script
I want to use pytest hooks like pytest_assertion_pass.
The workflow here for test execution is:
Another Python module run_test.py imports test.py and calls execute(). I cannot change that behavior.
...
0
votes
1
answer
128
views
How to have user log in once and then reuse the same session over different python-playwright browser tests?
Using
dependencies = [
"pytest>=9.0.2",
"pytest-playwright",
]
in a Python application I am setting a a browser end to end test.
I have defined custom markers:
[tool.pytest....
Advice
0
votes
2
replies
26
views
Where/how are pytest parameters for individual tests defined?
I really struggle with pytest's automagic definition of arguments for individual tests. For example, I have this test where I am mocking an external api call:
def test_valid_type(monkeypatch):
...
0
votes
0
answers
78
views
Pytest spark fixture failing on startup
I have been trying hard to test my PySpark transformation on my local Windows machine.
Here is what I have done so far.
I installed the latest version of Spark, downloaded hadoop.dll and winutils, ...
Best practices
0
votes
1
replies
85
views
Is it possible to configure pytest-cov to show coverage of data files?
A simple scenario to illustrate the core issue.
My project requires the user to provide a configuration file in YAML format.
I provide a sample configuration file, for example:
env: dev
cpu: 1
mem: ...
1
vote
2
answers
108
views
Mock not called by subprocess
An instance of class A starts a sub-process that calls a method of an instance of class B. It works as expected in real-life, but unit tests fail because the mock object replacing the object of class ...
0
votes
1
answer
205
views
How to make hatch test install the whl instead of directly using project dir?
With the AI answers, I was recommended to do:
[tool.hatch.envs.hatch-test]
dev-mode = false # This is the line recommended by AI to have it installed instead of having it editable/local use mode
...
0
votes
1
answer
162
views
nicegui.testing with User fixture for upload file ui.upload
Hello i am new on nicegui, i create a simple app where i need to upload the files and store this files on ftp server. I start to make some tests with nicegui.testing.User (i use this package because i ...