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...
Pedestrian asked 11/5, 2021 at 8:16

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...
Breakable asked 13/1, 2021 at 14:35

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...
Adelaidaadelaide asked 28/10, 2022 at 11:36

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...
Isocyanide asked 14/4, 2015 at 12:28

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...
Reams asked 11/10, 2013 at 1:17

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" %} ...
Photovoltaic asked 6/10, 2021 at 19:26

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...
Aborticide asked 22/2, 2019 at 16:29

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...
Massimo asked 28/5, 2024 at 10:12

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 ...
Sisyphean asked 12/12, 2019 at 17:6

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...
Polytrophic asked 19/6, 2015 at 12:57

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(&...
Southeastwardly asked 3/9, 2020 at 8:51

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...
Aorangi asked 11/2, 2016 at 11:9

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_...
Apperception asked 16/8, 2022 at 14:8

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.