Questions tagged [pytest]

For questions about the pytest Python testing tool. Please also add the [python] tag for questions tagged with [pytest].

Filter by
Sorted by
Tagged with
0 votes
0 answers
4 views

How to mock Kafka Producer and producer.send method in PyTests

I am using Python Django Project and I have Kafka implemented in my project. Now I am writing my pytest cases for APIs and functions. However, I am unable to mock the Kafka Producers and Consumers. I ...
NVS's user avatar
  • 400
0 votes
0 answers
20 views

Teardown objects that are created during parametrize method in pytest

I have a conftest.py file that includes an option for command line, given this option, it creates an N number of the same clients, but with different credentials, as such import pytest def ...
A. Yu's user avatar
  • 73
0 votes
0 answers
12 views

Properly run and kill background process in a python script/pytest

I am writing some unit tests for a python program that requires the background execution of a port-forwarding command to query a service. The program is a Kubernetes operator written in python using ...
Neah-Ko's user avatar
  • 45
-2 votes
0 answers
23 views

Which is a better testing frame work: Cypress or Pytest? [closed]

I am looking to choose a testing framework which would support the following requirements: UI automation API automation CI/CD support Opensource with good online community to discuss about (a good ...
Summa11's user avatar
0 votes
0 answers
40 views

django.db.utils.ProgrammingError: relation " " does not exist when running pytest

I am experiencing a very funny bug in Django. I have gone every way possible including resetting migrations. I have written a pytest for a Django project however the above error occurs when running. ...
The Elif's user avatar
0 votes
0 answers
28 views

How to mock a method called from a subprocess?

there is test, for example: class TestBlaBla(TestCase): def test_lala(self): output = subprocess.check_output(some_python_script_file, shell=True) ... Let's say in "...
Petro Bzdanovich's user avatar
-1 votes
0 answers
27 views

Pytest AssertionError [closed]

I am getting an AssertionError on my pytest tests, and was wondering if it's because the tests failed or it's because I didn't properly write the tests. I am new to pytest. Here's my code: def ...
Adam Sarhan's user avatar
1 vote
1 answer
30 views

how can I use fixture to create a mock file of certain size?

I'm doing something like this def test_collection_size(create_fake_file): files = [create_fake_file] size = get_collection_size(files) assert size == 32 create_fake_file fixture should ...
forgotten dinosaur's user avatar
0 votes
1 answer
56 views

'anyio' has no attribute 'start_blocking_portal'

One of my fast api endpoints is supposed to return a csv response. I try to check this endpoint but I get this error self = <starlette.testclient.TestClient object at 0x7f834a5f6ec0> @...
panos's user avatar
  • 368
0 votes
0 answers
43 views

pytest fails to discover tests

I try to make pytest discover the tests I've written, but keep getting an error message that I don't really understand. Some more details: platform win32 -- Python 3.7.16, pytest-7.1.2, pluggy-1.0.0 ...
Kozolovska's user avatar
  • 1,090
1 vote
1 answer
20 views

Mocking does not work as expected (Django)

I have this code: // app1.service.py database = { 1: "Alice", 2: "Bob", 3: "Charlie" } def get_user_from_db(user_id): return database.get(user_id) // ...
Ivan's user avatar
  • 27
1 vote
1 answer
36 views

Mocking json.dumps() method in Python unit tests [closed]

I am working on test case writing using Pytest and I need to mock a function which uses json.dumps() method. I tried so many ways but somehow this method cannot be mocked. I tried using decorator - @...
Pallavi's user avatar
  • 576
0 votes
0 answers
12 views

Pytest finding package directory but not calculating coverage

I am using pytest-cov to determine the coverage of my package. I have a directory structure that looks like this: ├── dev_environment.yaml ├── pyproject.toml ├── README.md ├── setup.py ├── src └── ...
Austin Benny's user avatar
0 votes
1 answer
21 views

Python pytest - ModuleNotFoundError: No module named 'prompts'

Running pytest in the terminal results in the below error. The application runs fine with python3 main.py from the src/ directory, however pytest throws this error. ...
Luca's user avatar
  • 97
0 votes
0 answers
45 views

Testcases skipped:Issue on applying Pytest-dependency and Pytest-Ordering

Tried intergrating pytest-dependency and pytest-ordering in my testcases that are in different python files and issue below rises where dependent testcases are skipped. Seen similar issues here in ...
Taiwan004's user avatar
-1 votes
0 answers
30 views

E AttributeError: 'Test_Login' object has no attribute 'driver'

When i'm trying to run my code using pytest framework which is as below, i'm facing the Driver Attribute issue. Request your help in fixing this issue. All the browser setup is in the conftest.py file....
Satish Ghanta's user avatar
0 votes
1 answer
49 views

operational error when testing my CLI app with a SQLite DB

So I wanted to add tests to my CLI app, but I am struggling to replace my db with a temporary one. So far I have used SQLModel for database access, but for the app testing I want to assert the db ...
Jan's user avatar
  • 375
0 votes
0 answers
28 views

Pytest : breakpoint() don't stop the test execution

I'm fairly new to Pytest, and I guess I'm missing something obvious here. When I set a breakpoint() in my application code, and then launch my tests with pytest, the breakpoint is showing in my ...
Ruff9's user avatar
  • 1,153
0 votes
0 answers
29 views

Pandas read_table never fails

Trying to learn a bit of python and test that the incoming binary data ( which is a file ) is tab-delimited. Whatever kind of string I turn into binary does not break the pandas read_table parser. I ...
godhar's user avatar
  • 1,191
0 votes
1 answer
24 views

mock a class in python that used by other class

I am trying to mock a function on a class that calls a function that is in other calls a method of other class as shown below. class check: def __init__(self): asdad def b(self): ...
tanuj gupta's user avatar
0 votes
0 answers
14 views

pytest mocker.patch not working for Vault

I am new to pytest and unittesting and having an issue below (fake and simplied version of code): app.py from vault import Vault vault = Vault(role_id, secret_id) def function_to_be_tested(): ...
user10420421's user avatar
0 votes
1 answer
32 views

ImportError: No module named 'Shapes' when running Python scripts and tests

Description: I'm encountering an ImportError issue in my Python project related to module imports. The project structure is as follows: C:. ├───Shapes │ │ Circle.py │ │ Rectangle.py │ │ ...
Jovan Tatic's user avatar
0 votes
4 answers
67 views

How to add env variable to pytest in vscode for the side bar?

I created launch json for tests in vscode and it works well in terminal, but vscode don't see tests in the side bar, becouse side bar don't get environment variables from launch.json. How to add ...
Piter's user avatar
  • 59
0 votes
0 answers
47 views

Pytest-dependency between test scripts files

Seen others saying it's impossible to use pytest-dependency between test scripts. But I tried an alternative to import and initialise other classes from different script files (Page_1 & Page_2) so ...
Allegra Vaughn's user avatar
-1 votes
1 answer
28 views

how do i mock requests.get().url with side_effect?

I have the following code: def consuming_api_swapi_index_page(initial_page: int = 1): """Swapi index page.""" check = HTTPStatus.OK results = [] while ...
britodfbr's user avatar
  • 1,821
1 vote
0 answers
53 views

ImportError: No module named 'src' when running pytest in GitHub Actions

I am encountering an issue when running my Python tests using pytest in GitHub Actions. The tests work correctly on my local machine, but in the GitHub Actions workflow, I receive an ImportError: No ...
Roni Jack Vituli's user avatar
0 votes
0 answers
11 views

What classes are the databases specified in the pytest.mark.django_db databases parameter wrapped in?

Having the following test : @pytest.mark.django_db(databases=["mongodb", "default"], transaction=False) def test_mutation_response(): assert PostgresQlModel.objects....
Julian Steven Mojica's user avatar
0 votes
0 answers
12 views

Pytest add arguments to playwright browser

How to send a browser argument to a browser from playwright under pytest? For example: I need to call firefox --profile=/directoryofmyprofile
Hola Soy Edu Feliz Navidad's user avatar
-5 votes
0 answers
40 views

Modules or classes for Page Objects in Python [closed]

I can implement Page Objects in Selenium with Python in 4 ways: Creating Page Objects as modules and test files as modules Creating Page Objects as classes and test files as classes Creating Page ...
Vladimir's user avatar
  • 620
0 votes
0 answers
59 views

Pytest: Correct way to Mock a function called within a function to return what was passed into it

I am new to Pytest and am trying to figure out how to make a function called within a function perform nothing. Here's an example that illustrates my overall goal. def add_one(n): return n+1 def ...
trey hannam's user avatar
-3 votes
0 answers
31 views

pytest import module [closed]

I'm trying to import a module into my test file. This is the content of the file path; I mean, I'm in conftest.py ├── x1 │ └── python1.py └── tests └── lambdas └── core └── ...
Azize Lbaibi's user avatar
0 votes
0 answers
10 views

pytest-mock combined with pytest-qt: call mock after function has executed

I would like to call the function that is mocked before the mock is called. What is the best way to do this? main.py import logging import sys import sys from PyQt6.QtWidgets import QApplication, ...
Håkon Hægland's user avatar
0 votes
1 answer
35 views

Running own conftest for every application

I have several applications in my project each application has its own tests: app/tests/test_block1.py test_block2.py ... And every tests folder has its own conftest.py I want to drop database for ...
Konstantinos's user avatar
0 votes
0 answers
16 views

how to configure pytest to get the exceptions summary after the logs

By default, pytest hides the stdout/stderr logs during the test execution, and only shows them after the failure summary. Is there a way to swap the order? Specially when there are many failures and ...
Daniel Pinyol's user avatar
0 votes
0 answers
33 views

pytest does not see the webdriver from the different file

I have a simple code setup_test.py that perfectly works in the common package from selenium import webdriver driver = None def setup_function(): print("Setup") global driver ...
Vladimir's user avatar
  • 620
0 votes
1 answer
33 views

python PyTest lask for login page for each Test module

I am new to python. I have requirement that login must be done before running the all the test. i.e. on class level. if i have two test file TEST_F1 , TEST_F2 then when i run the test the login ...
Sanjay Prakash's user avatar
0 votes
2 answers
39 views

How to override dependency APIRouter level in pytest?

I am writing test cases for FAST API endpoints. One of my module file cud.py from fastapi import APIRouter from auth.jwt_bearer_default import JWTBearerDefault router = APIRouter( prefix="&...
todayforfuture's user avatar
0 votes
0 answers
13 views

PermissionError in window after pytest

I am running the python project with pytest but there is permession error. I try with fixed with assined the fully permession still the same issues. these issues related to pytest. I check the ...
Tech knowledge's user avatar
0 votes
1 answer
58 views

Where is the request argument coming from in pytest fixtures?

I have a question with the request argument in the following code: @pytest.fixture(scope="module") def run_id(request): return request.config.getoption("--run-id") In that ...
tjt's user avatar
  • 628
-1 votes
0 answers
94 views

Pytest not discovering test classes with custom decorators

I have the following decorator: def orchestrate(cls): @functools.wraps(cls) def wrap(*args,**kwargs): print("Here") cls.orchestrator = "Some Value..." ...
Adventure-Knorrig's user avatar
0 votes
1 answer
22 views

composite strategy doesn't work as planned

trying to create a rather complex strategy using python's Hypothesis doesn't work as planned. the strategy is a fixed_dictionaries (recursive_strategy) where some of the dictioneries 'values' are ...
hadromi's user avatar
  • 11
0 votes
0 answers
22 views

Using mock.patch.object() with sqlalchemy model

class FooModel(Base): __tablename__ = "foo" __table_args__ = { "schema": "some_schema", "postgresql_partition_by": "RANGE (event_ts)...
mehekek's user avatar
  • 175
0 votes
1 answer
51 views

Preferred method for raising Python Exception from many codepaths?

I am writing code in Python, using PyTest for testing. Suppose I am performing some task that may fail in many possible ways. I have a function that performs this task, and counts the number of times ...
pluto_projector's user avatar
0 votes
1 answer
18 views

How to see print statements using pytest-watch?

While debuging my python code, I'm trying to see the print statements while running the tests. If I run pytest -s or pytest --capture=no I can see my prints as expected but when I try to pass the ...
Gustavo Melo's user avatar
0 votes
0 answers
20 views

Unable to build using python-app.yml in git

I have a simple python application that will read json file from a folder path, create dataframe out it and test the schema of the dataframe. I am using python-app.yml in git actions to build and test ...
awesome_sangram's user avatar
0 votes
1 answer
58 views

Is there a way to override top level dependencies in FastAPI?

In this FastAPI app we use Auth0 to authenticate, so it is a top level dependency. Is it possible to override it in a test? I setup FastAPI following this guide: https://auth0.com/blog/build-and-...
creyD's user avatar
  • 1,994
0 votes
0 answers
39 views

Pytest: Calling super() within inheritted class fixtures

I have a lot of similar groups of tests and would like to make a more general parent test collection as a class. In the class, I'd like to group the fixtures as well, but in some child classes I need ...
artemisbrunch's user avatar
0 votes
1 answer
25 views

Unable to generate Allure-results files with Pytest in Mac

So i got a mac pro with m2 chip framework is selenium with Python earlier in windows i was able to generate the report by navigating to the tests folder and running below command in cmd "pytest -...
saffin's user avatar
  • 1
0 votes
0 answers
67 views

Use fields Owner and Tag on Azure Pipelines test report

I'm using pytest-nunit to generate a test report in azure pipelines. and I noticed two fields (Owner and Tags) that I would like to use, but couldn't find any documentation. Any idea on what azure ...
ggoulart's user avatar
0 votes
0 answers
18 views

Moto and boto3 mocks only when specifying the specific python file

I'm using moto to mock my aws calls in my unit tests. When i run pytest tests/test_file.py the unit test will be successful and boto3 gets mocked. When i run pytest tests/ to detect all the test files ...
dwardu's user avatar
  • 593

1
2 3 4 5
201