All Questions
3,540
questions
0
votes
0
answers
29
views
Django Internationalization test error:Couldn't retrieve redirection page
I wrote a blog project in Django,in some pages i used loginrequierdmixin to make sure user is loged in but in test i got error
test:
def test_get_profile_unauthenticated(self):
response = ...
-1
votes
0
answers
28
views
FastAPI dependency is not getting overriden [SOLVED] [closed]
I'm trying to run some tests with pytest against the API but my dependency override is not working. The root app is in my 'main' file and the endpoints are in a 'routers' file. I also have a separate '...
0
votes
1
answer
30
views
How to test Amazon Athena queries
I have a rather complicated Athena query, which I would like to test on a local machine without connecting to Athena. I specified some mock data for testing purposes, and I was hoping that I could use ...
1
vote
0
answers
24
views
mocking out imported objects in Python
Lets say there is a module headache that defines an object that is then imported and used by code I want to test:
# defined in headache/__init__.py
problem = Problem()
then it's imported by Foo:
# ...
1
vote
2
answers
63
views
How to mock sqlalchemy's async session?
Code snippet
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
engine = create_async_engine(url="")
session_maker = async_sessionmaker(engine)
How can I mock the ...
0
votes
0
answers
28
views
How to list all futures that are being polled inside specific event loop when running pytest?
I'm running multiple pytest tests.
I have 1 specific test case, which works fine when executed alone, but when large amount of previous tests are being executed, this particular test gets stuck when ...
1
vote
1
answer
24
views
Cannot mock the method in dependency module correctly in Python
Here is my project structure
|-- project
|-- util.py
|-- main.py
|-- tests
|-- test_main.py
In the main.py file I reference the function in util.py
from util import rename
def ...
1
vote
1
answer
132
views
Robot Framework is Automatically closing the browser
I am new to Robot and have this simple code from a tutorial. The code is supposed open chrome and visit the login page of this website. It does that, however, it closes the browser automatically. I've ...
0
votes
0
answers
40
views
Why python testing always import the file in another module implicitly
Current I have two files in the same folder, in the source file I import the dlt module
# File: pipeline.py
import dlt
Another is a test file which import nothing from the source file yet:
import ...
1
vote
1
answer
30
views
Django session in tests
everyone!
I can't figure out how the sessions work in Django.
I have a shop, an anonymous user's shopping cart is bound to session_key.
The session key is taken from the request object.
def ...
0
votes
0
answers
24
views
Why 'coverage' considers all of my class-based-views as tested?
I'm just learning django testing.
When I use 'Coverage' module to check which parts of my code is tested, it considers almost all of class-based-views as tested while I have commented out all of my ...
0
votes
1
answer
33
views
AssertionError while testing forms.py in Django
I tried to test forms.py in Django which has LeadForm class.
Here, is the models.py
class Lead(TimestampedModel):
"""leads for LIVE courses"""
course = models....
-1
votes
1
answer
27
views
Flask unit test failing due to FileNotFoundError for private key file [duplicate]
I'm trying to run unit tests on a Flask application that utilizes public and private keys for JWT token generation. However, when running my unit tests, I'm getting a FileNotFoundError indicating that ...
0
votes
0
answers
23
views
testing django oauth2_provider authentication endpoint
I need to test o/token endpoint of the oauth2_provider. I wrote the test in pytest. I think I considered every thing but I get invalid_client error.
The code:
factory:
class UserApplicationFactory(...
0
votes
0
answers
47
views
How to parse step definition code for projects using Cucumber?
I'm working on a project where I want to evaluate how Behavior Driven Development is being used. I want to extract Gherkin steps from .feature files and match the underlying step definition code. For ...
1
vote
1
answer
28
views
DRF test user sign-in, error inactive user
I have view for authentfication:
class UserViewSet(viewsets.ViewSet):
@method_decorator(sensitive_variables("password"))
@action(url_path="sign-in", detail=False, methods=[&...
0
votes
0
answers
40
views
"AssertionError: Expected 'show' to have been called once" when trying to mock plt.show()
I am currently trying to design some tests to run with pytest for a GUI. The GUI has a button that plots a graph on click. I want to make sure the button does indeed generate a graph. At this stage, I ...
2
votes
0
answers
29
views
Changing the scope of a pytest fixture to a larger one for a single module
I have a pytest fixture defined in conftest.py that looks like this:
@pytest.fixture(scope="function")
def setup_multiple(create, delete):
@contextlib.contextmanager
def f(type, num=...
0
votes
0
answers
11
views
How to get pitest-bdd to run a directory of .feature files against a single Python test script
Sorry i am new to to pytest-bdd and am having trouble finding resources on how to run a directory of .feature files against a single Python test script.
Example of one of these feature files:
Feature:
...
0
votes
1
answer
46
views
Mock patching an endpoint unittest that makes several requests to third party
I have a single endpoint written using django ninja. This endpoint executes a crawler that performs several requests. The sequence of requests has 3 different routines depending on whether or not the ...
0
votes
1
answer
33
views
@pytest.mark.parametrize for function that returns two values
I have a function that takes a pandas DataFrame (it is important that this specific DataFrame, that goes as an argument into the function, has no column names) and produces a DataFrame with column ...
0
votes
0
answers
25
views
How to compare in Python to TypeError using assert? [duplicate]
I write tests using Assert. How do I compare to TypeError ?
Function
def calc_of_the_cost_of_delivery(distance: int, size: str, fragility: bool, workload: str) -> int:
....
if distance > 30:...
1
vote
2
answers
47
views
Pretty print why two objects are not equal
When using pytest, I get nice pretty printing when two objects are not equivalent:
Expected :Foo(id='red', other_thing='green')
Actual :Foo(id='red', other_thing='blue')
<Click to see difference&...
0
votes
0
answers
42
views
Python unittest how to mock function which external function is defined in __init__.py
I would like to test my_func2 that is calling my_func1. I would like to mock my_func1, but I don't know how can I do it when my_func2 is imported in my_package.__init__.py. When I delete that import, ...
0
votes
0
answers
44
views
Django Token authentication failure: Authentication credentials were not provided
I am working on the user logic of my Django project. Despite the fact that logout (using session cookie authentication) works perfectly fine in the browser, it is not working during testing for some ...
0
votes
0
answers
29
views
How to test a CLI app with Typer and Questionary?
I have created a CLI app using Typer in Python. Among other things, it should be possible to create new records. For querying the individual properties, I have used the Questionary package. The CLI ...
-3
votes
1
answer
61
views
Find a word with three consecutive double letters using Python
This is a question from Think Python: How to Think Like a Computer Scientist by Allen B. Downey
Give me a word with three consecutive double letters. I’ll give you a couple of words that almost ...
0
votes
0
answers
20
views
Testing a Python package dependent on user input credentials
I maintain a Python package for other data scientists and analysts in my company, which simplifies access to S3/Hive/Trino. The package works by taking their credentials, storing them using keyring, ...
0
votes
1
answer
79
views
Use multiple AsyncClients with Pytest for Integration testing
I want to use two different httpx clients one which interacts with the actual database and other which interact with test database. But for some reason all the transactions happen on the actual ...
0
votes
0
answers
36
views
pytest how to implementation a plugin to execute by every directory
My project struct like
.
├── test_dir_1
│ ├── conftest.py
│ ├── test_case_1.py
│ └── test_case_3.py
└── test_dir_2
├── conftest.py
└── test_case_2.py
conftest:
import pytest
from loguru import ...
1
vote
1
answer
84
views
Pytest monkeypatch a multiprocess function for testing
Pytest monkeypatching a function that uses multiprocess (via concurrent.futures.ProcessPoolExecutor) does not work as expected. If the same function is written with a single process or multithread (...
0
votes
2
answers
59
views
Multiple if-raise statement
I wrote a python code with the following format:
if a1 in list1:
if b1 == 1 and c1>1:
raise Exception ('invalid c1 for b1')
elif b1 == 2 and c1>2:
raise Exception ('...
0
votes
1
answer
49
views
VS code python error can't find imported file
So I am using python and I have the following schema of files:
- 10.Testing (parent folder)
-- files (folder)
|__ __init__.py (empty file)
|__simple_functions.py
-- tests (folder)
|__ ...
-1
votes
3
answers
338
views
test chrome issue within chromedriver [duplicate]
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
driver_path = r"C:\Users\hp\Desktop\Udemy\chromedriver.exe" # Replace with your correct path
# Create a ...
0
votes
1
answer
59
views
pytest fixtures in nested Classes
I have written the following testcase using pytest.
import pytest
data_arg = ["arg1", "arg2"]
class TestParentClass1:
@pytest.fixture(scope="class", params=data_arg,...
0
votes
1
answer
21
views
Can I get access to a pytest hook to inject my logic AFTER the junit XML results file has been created?
From reading the docs I see that the latest hook after a test class has completed is pytest_runtest_logfinish. However, when I implement that hook and use the debugger, I see that the XML file (...
0
votes
0
answers
23
views
Mock or stub a QEvent?
Is there a way to mock a QEvent and pass it as a parameter?
I have a test like this which I want to include:
def test_table_resize_event_sets_column_widths():
table = results_table_classes....
1
vote
1
answer
49
views
Increasing test coverage for files I didn't write
I have written a python program that calculates various statistical values of a given list of integers and the range of values. Now, I am trying to write a test file for the program that can achieve &...
0
votes
0
answers
144
views
'dict object' has no attribute 'test_name'. This can happen when calling a macro that does not exist. Check for typos and install package dependencies
I'm calling a test within a model column in my schema.yml file, however, when running a "dbt compile" it says it doesn't find the test in the macros folder, and I configured that the tests ...
1
vote
0
answers
30
views
How to use multiple API modules in a single testing file?
Disclaimer: first Stack Overflow post, and very new to pytest.
I'm a part of a very new QA team in the company. Right now we are focusing on creating initial tests for various Sync APIs (most of them ...
0
votes
1
answer
26
views
firestore how to get list of orphaned documents
I am developing a firestore CLI tool called firebatch
I read that to properly delete a collection and to avoid orphaned documents, you have to traverse all subcollections and delete them first.
I have ...
0
votes
0
answers
131
views
Python tests failing due to testcontainers-postgres connection refused
I am trying to run integration tests by using PostgresContainer from the testcontainers module in Python. These tests are part of the CI workflow on Github Actions but they are failing due to the ...
0
votes
0
answers
88
views
load testing for burst requests using locust
I am trying to simulate a burst request in locust of 1200 with request rate of 600 per second
@task
def send_burst_request(self):
def send_request():
self.client.get(
...
0
votes
3
answers
55
views
Pytest: When writing many assert statements in the same test function, some of it fails, but how to know which assert statement/s is causing failure?
Test file :
from RansomNote import Solution
def test_canConstruct():
sol = Solution()
assert sol.canConstruct('aa', 'aab') == True
assert sol.canConstruct('xx','aaabc') == True
assert ...
0
votes
0
answers
41
views
webdriver error while working with selenium with python
I am getting this error
C:\Users\Admin\PycharmProjects\Testing\.venv\Scripts\python.exe C:\Users\Admin\PycharmProjects\Testing\firsttest.py
Traceback (most recent call last):
File "C:\Users\...
-1
votes
1
answer
56
views
Django test TypeError: Field 'id' expected a number but got ()
I got this error 3 times in my code. I searched on other question and I didn't find anything that worked.
Does anyone have any idea?
Thank you.
models.py
class Exam(models.Model):
code = models....
0
votes
0
answers
33
views
Mocking a dictionary upon FastAPI router instantiation
Attempting to write tests for an existing route and running into some roadblocks. I'm trying to mock a dictionary that is loaded when a router is instantiated, but it seems like the @patch'd versions ...
-1
votes
2
answers
52
views
AssertionError: 404 != 200 in django testing
I have test code, but it displays error:
self.assertEquals(response.status_code, 200)
AssertionError: 404 != 200
class TestViews(TestCase):
def setUp(self):
self.client = Client()
...
0
votes
0
answers
20
views
Tox tests working behaviour for changes in basepython field is a confusion
I have tox file which have a code like this
[tox]
envlist = py38,py39,py310,pep8
minversion = 3.1.0
skipsdist = False
[testenv]
basepython = python3
Earlier it was working like this, ...
-1
votes
1
answer
60
views
Pytest ignoring certain parameters with multiple parametrize
Im wondering if there's any way of skipping parameter pairs in the example below:
@pytest.mark.parametrize("foo", [1, 2, 3])
@pytest.mark.parametrize("bar", [4, 5, 6])
When ran ...