pytest Questions
2
In the pytest documentation it says that you can customize the output message when an assert fails. I want to customize the assert message when testing a REST API method it returns an invalid statu...
Adelric asked 13/6, 2017 at 12:39
5
Solved
While running a particular unittest with pytest, it occasionally fails with this error (mentioned in the title) and from the stack trace it happens on the line
choice = input().lower()
when the c...
Calcium asked 18/7, 2018 at 2:52
2
Solved
I have been using pytest-mock library for mocking with pytest. When I'm trying to run the test using tox command, I am getting the following error:
...
tests/test_cli.py ....EEEE
...
file /path/to/...
Practically asked 18/10, 2020 at 19:38
6
I'm new to testing and I've stumbled across pytest fixtures, but I'm not entirely sure when to use them and why they're useful.
For example, see the below code:
import pytest
@pytest.fixture
def i...
Triacid asked 14/6, 2020 at 17:55
10
Solved
I have a test to verify an exception is thrown from an async response, which I'm using pytest-asyncio version 0.10.0 to run.
Code is basically:
class TestThis:
@pytest.mark.asyncio
def test_the...
Certes asked 4/4, 2020 at 1:27
4
Solved
We run tests on each pull request in github.
It would be very cool if the coverage would be visible if you are looking at the changes of a pull request.
While looking at the diff in the PR review I...
2
My project structure:
cool_project/
tests/
cool_dir/
test_cool.py
conftest.py
test_main.py
I'm using pytest version 6.2.1, and python 3.8.7. I have a conftest.py, containing pytest_sessionst...
3
I'm seeing that assertion messages do not seem to be displayed if the assertion occurs in a helper method within the same module as my test when in PyCharm.
This only seems to be happening in PyCha...
5
Solved
Testing function I need to pass parameters and see the output matches the expected output.
It is easy when function's response is just a small array or a one-line string which can be defined inside...
3
The py.test assert docs say
... if you specify a message with the assertion like this:
assert a % 2 == 0, "value was odd, should be even"
then no assertion
introspection takes places at a...
4
Solved
In my project I'm parsing some PDF files using pdfplumber. During tests execution (pytest) I sometimes would like to see logs from my code for debugging purposes. This can be done by setting --log-...
Bum asked 12/7, 2019 at 6:33
2
Solved
I have a CMake based project that uses both C++ and python sources. Tests are added via add_test for all C++ tests in a folder structure like:
src
mynamespace/foo.cpp
mypyspace/mypkg/__init__.py...
Stendhal asked 25/9, 2018 at 9:6
3
I am trying to run a test suite for django that uses inlinecss. inlinecss references a static file in the template as follows:
{% load inlinecss %}
{% inlinecss "css/emails/base.css" %}
...
4
Solved
How do I define async fixtures and use them in async tests?
The following code, all in the same file, fails miserably. Is the fixture called plainly by the test runner and not awaited?
@pytest.fi...
Maryammaryann asked 20/4, 2018 at 7:53
4
this is an expansion of How do I find where a "Sorting because non-concatenation" warning is coming from?.
I'm still getting the same warning, in my pytest. I've looked at several quest...
3
Solved
(The following code can be run in Jupyter.)
I have a class B, which uses class A, needs to be tested.
class A:
async def f(self):
pass
class B:
async def f(self):
a = A()
x = await a.f() # ne...
Flinty asked 5/2, 2022 at 4:59
0
This relates to pytest - Windows fatal exception: code 0x8001010d but i narrowed the error down to the simplest program.
from PyQt5 import QtWidgets
q_app = QtWidgets.QApplication([])
def test_wi...
5
I have a handful of fixtures in conftest.py that work well inside actual test functions. However, I would like to parameterize some tests using pytest_generate_tests() based on the data in some of ...
4
Solved
py.test's --verbose option is required to show full diffs on assertion failures, but this also displays the full name of each test during execution (which is noisy).
I'd like full diffs to show wh...
4
I would like pytest-django to install a Postgres extension when it creates a test database. I've been mucking with conftest.py to try to get this to work, but I'm stuck.
My conftest.py is at the t...
Fuqua asked 30/1, 2017 at 15:55
3
I try to add use pytest parametrize for my unit tests. But I see the error of "missing required positional arguments". Can you help where the issue is? Thanks.
@pytest.mark.parametrize(&...
3
How can I get VS Code to put me into the debugger at the point of failure when running tests with pytest?
Pytest catches all errors and asserts, and VS code invokes the debugger only on uncaught er...
Bazil asked 27/8, 2020 at 15:36
3
I have a module inside a package which figures out the path of the invoking python program:
pathname = os.path.dirname(os.path.realpath(__file__))
from where it will pick up a mydata.json to rea...
5
Solved
I'm reading env variables from .prod.env file in my config.py:
from pydantic import BaseSettings
class Settings(BaseSettings):
A: int
class Config:
env_file = ".prod.env"
env_file_...
2
Solved
I am working on a command-line shell, and I'm trying to test some functions that parse command arguments.
parser.py:
import shlex
import click
def process_cmd(args, called_self=False):
result = ...
Elliellicott asked 28/11, 2019 at 20:53
© 2022 - 2025 — McMap. All rights reserved.