Skip to main content
Stack Overflow for Teams is now Stack Internal: See how we’re powering the human intelligence layer of enterprise AI. Read more >
Filter by
Sorted by
Tagged with
1 vote
1 answer
117 views

Sometimes when I develop by TDD (Test Driven Development) I need to test the calling order of some class methods. In general I write Python code so I'll show the last test case that I have just ...
User051209's user avatar
  • 2,658
-1 votes
1 answer
31 views

I have come across this problem when making my unit tests. from unittest.mock import AsyncMock, patch import pydantic # class Parent(): # Using non-pydantic class works class Parent(pydantic....
Automatico's user avatar
  • 12.9k
0 votes
1 answer
73 views

I have the following directory structure when I use the test runner I get File "/home/kyle/dev/tests/test_foo.py", line 2, in <module> import foo ModuleNotFoundError: No module named ...
user1604008's user avatar
  • 1,151
1 vote
1 answer
62 views

I have a Model class with a series of constraints that I am attempting to test, and I am unable to get these constraints to return an IntegrityError in testing. The class is as follows: from django.db ...
dabo_tusev's user avatar
1 vote
0 answers
60 views

We have several modules that require mandatory feature / backout flags. These flags are defined at module level. module.py: from enabled import is_enabled FLAGS = {flag : is_enabled(flag) for flag in ...
OM222O's user avatar
  • 1,003
-1 votes
1 answer
81 views

Closely related to my question is VSCode: how to interrupt a running Python test?, however in my case the standard method of pressing the square in the Test Results tap does not work. What is ...
Daraan's user avatar
  • 5,126
1 vote
0 answers
80 views

I'm building a backend system using FastAPI, and I'm currently working on implementing unit tests for the password reset functionality that involves using tokens. Here’s the snippet of the code I'm ...
Hiroshi Ashikaga's user avatar
0 votes
1 answer
74 views

I have a configuration module, config with data config.data where I want to add a value for testing. Ideally, I want to use mock.patch.dict as a context manager because the value is a class attribute ...
KSS's user avatar
  • 179
4 votes
1 answer
395 views

I have been working on yet another API using FastAPI and trying to write test cases for the APIs, but facing error that event loop is closed. My setup: So, I am using asyncpg driver/library to connect ...
Super Ultra Noob's user avatar
1 vote
0 answers
85 views

I tend to alwasy run the testers from inside the module folder, but this breaks the "resources.files" functionality, as it seems not to be able to find the module any more module folder ...
hewi's user avatar
  • 1,446
1 vote
2 answers
49 views

I know how to use coverage module to get "human readable" coverage output (using popular third party coverage module). This can be used with pytest or unittest (with some differences in the ...
Amit's user avatar
  • 2,138
1 vote
1 answer
64 views

I have a custom class in the file MyClass.py class MyClass: def __init__(self): self.fetched_data = False def get_data(self): self.fetched_data = True ...
DwightFromTheOffice's user avatar
0 votes
2 answers
61 views

I'm writing because I have a big problem. Well, I have a project in Django where I am using django-tenants. Unfortunately, I can't run any tests as these end up with the following error when calling ...
Draqun's user avatar
  • 364
1 vote
1 answer
179 views

I want to mock asyncio.sleep to shorten the delay, e.g. by a factor of 10, to speed up my tests while also trying to surface any possible race conditions or other bugs as a crude sanity check. However ...
Joe C.'s user avatar
  • 501
2 votes
1 answer
44 views

We can check if a unittest.mock.Mock has any call with some specified arguments. I now want to test that some of the arguments are correct, while I do not know about the other ones. Is there some ...
502E532E's user avatar
  • 581
1 vote
1 answer
60 views

My project structure: ├── core | └── service | └── file.py └── tests └── test_file.py I have a function fun that uses a class method. file.py from another_module import myClass ...
rhar's user avatar
  • 9
0 votes
1 answer
114 views

I have a scenario where I create a git.repo.base.Repo object in a "someFile.py": def someFunction(): //some part of code repo = Repo(path) repo.head.reference = repo.commit(...
Shiva Shukla's user avatar
0 votes
0 answers
23 views

In odoo 17 I need to use unitest.mock to mock the return value of a function The function is called cfdi_cancel. It is located in mymodulename module, inside that module is the 'models' folder, inside ...
Ernesto Ruiz's user avatar
0 votes
0 answers
66 views

I keep getting failed test results with a correct output. I.e: ====================================================================== FAIL: test_block_to_block_type_code (tests.test_block_parser....
Fernando Castro's user avatar
1 vote
1 answer
46 views

I've faced a problem. In my situation I create testcases dynamically like this class TestMetrics(unittest.TestCase): @staticmethod def generate_test(test: ElementaryTestCase): def ...
Егор's user avatar
0 votes
1 answer
92 views

I have problems when testing the way in which I choose the db to connect to in a condition of my scope where I will perform the deplyoment: from app.resources import secrets from app.resources.scope ...
Juan David Serna's user avatar
0 votes
0 answers
25 views

I am looking for a way to mock db_session in pony. An example I have now is the following test method: import unittest from unittest.mock import MagicMock from mock import patch from fireguard....
torva's user avatar
  • 13
1 vote
2 answers
129 views

My code tries to make HTTP requests to Gitlab API to make different actions such as create projects, branches, milestones etc. I'm not using external modules like requests because I want to keep my ...
wavesinaroom's user avatar
0 votes
0 answers
40 views

I am new, really new to the programming field (I just went through a QA Automation course with Python) and I am trying to work on a Unittest suite, but when I try to run an individual test (Ex: ...
MirceaUn's user avatar
0 votes
0 answers
35 views

I am having an issue where the patch method from the unittest.mock module is only working when I patch attributes of imported modules in other files. I do not understand if this is an issue of my ...
R T's user avatar
  • 11
0 votes
1 answer
27 views

In my test I want to verify that no error log was done during the test. How do I do that? I tried with self.assertLogs("", level="ERROR") as error_logs:. This can capture the error ...
DarkTrick's user avatar
  • 3,683
1 vote
1 answer
140 views

I want to mock: async with aiohttp.ClientSession() as session: async with session.post("xyz.com") as resp: x = await resp.json() Currently, I am doing: # patched aiohttp as ...
Joe C.'s user avatar
  • 501
0 votes
1 answer
33 views

I'm trying to assert all paths that passed through os.makedirs to test that a folder structured has been created. The code isn't complicated and I'm sure it works find but my test reports that the ...
wavesinaroom's user avatar
0 votes
1 answer
50 views

I'm trying to mock some objects in unittest but I need to have a different boolean value returned depending on the Mock object being evaluated in an if statement. The function I'm testing looks ...
RoyalSwish's user avatar
  • 1,583
0 votes
1 answer
20 views

I'm creating files with pathlib.Path.touch with the following method that I'd like to assert in a unittest using unitest.mock.patch decorator: sessions.py def generate_folders(paths: list): for p ...
wavesinaroom's user avatar
0 votes
0 answers
79 views

I have Python code that works locally and when run on Databricks. For saving the results, a different function is used depending on where to code is run. On Databricks, several things are ...
Julian's user avatar
  • 613
0 votes
1 answer
101 views

I am setting up a Python project in VisualStudio Code. My folder and file structure looks like follows: Base project folder source_folder package1_folder module1.py package2_folder module2.py ...
Blackbriar's user avatar
-1 votes
1 answer
49 views

I am currently writing a pytest file and need some help regarding it. In my conftest.py I am initialising the spark session in a function let's session def session(): spark - Spark.Session ... My ...
u09j's user avatar
  • 11
2 votes
3 answers
133 views

I am trying to test some python code that involves setting/comparing dates, and so I am trying to leverage unittest.mock in my testing (using pytest). The current problem I'm hitting is that using ...
scotscotmcc's user avatar
  • 3,163
1 vote
1 answer
89 views

I'm working on a project that uses pyfakefs to mock my filesystem to test folder creation and missing folders in a previously defined tree structure. I'm using Python 3.13 on Windows and get this ...
wavesinaroom's user avatar
-1 votes
1 answer
44 views

I'm trying to figure out how to use the Patch decorator (or in general the unittest library) for the following python code (I'm using 3.5 version): class C: def __init__(self): self....
smark's user avatar
  • 15
0 votes
0 answers
20 views

I am trying to write unit tests for my python CDK code. From the AWS doc I understand that templates are generated easily for the level-2 & level-1 constructs so that the template can be tested. I ...
Mukund Jalan's user avatar
  • 1,369
2 votes
1 answer
194 views

I'm working on writing test cases for some Python code that uses asyncio. I'm noticing a significant performance degradation when my test classes inherit from unittest.IsolatedAsyncioTestCase vs. ...
Mike's user avatar
  • 61.3k
0 votes
1 answer
178 views

How to use QtTest.QSignalSpy with unittest? It is not clear from the documentation; there are few examples. from PySide6.QtWidgets import QApplication, QLabel, QWidget, QVBoxLayout, QPushButton from ...
Garp's user avatar
  • 267
0 votes
0 answers
50 views

I'm trying to write a unit test with unittest which tests that the behaviour of the below function only opens files that have a filename pattern of test_*.json. import glob import json def get_tests()...
RoyalSwish's user avatar
  • 1,583
1 vote
1 answer
106 views

I have an app/main.py for FastAPI which does: import qdrant_client as QdrantClient ... qdrant_client = QdrantClient(url=...) qdrant_client.create_collection(...) ... app = FastAPI() ... @app.get(&...
Clovis's user avatar
  • 4,483
0 votes
1 answer
69 views

I'm trying to use and test sockets in python (I have to use 3.5 version). Consider this code: import socket def send_recv(xml_message): try: address = ('127.0.0.1', 12000) ...
smark's user avatar
  • 15
1 vote
1 answer
65 views

How can I mock an import error of the module foo in the unit test? # file: bla.py try: import foo except ImportError: print("error") sys.exit(1) Baseline for the unit test: ...
fsdfsdfsdfsdfsdf's user avatar
0 votes
1 answer
43 views

I have a super simple test framework in VSCode as follows: /.vscode launch.json settings.json /python /resources some_data.tsv /src myapp.py /test ...
yeliabsalohcin's user avatar
0 votes
1 answer
126 views

Is it possible to declare a local variable before it's imported? For example to get this code to run as expected: # a.py # do magic here to make b.foo = "bar" import b b.printlocal() # b....
Brett S's user avatar
  • 589
0 votes
2 answers
66 views

Let's say you want to test a function that requires input and another that prints output. This requires two different patches. I created two distinct classes, but only 1 of them runs. The sample ...
user1079785's user avatar
0 votes
2 answers
169 views

I have tried to run a program using pytorch. It stopped with the error 'No module named "unittest.mock"' Then I wrote a minimal python program: import unittest.mock if __name__ == '__main__':...
Hamatoma's user avatar
1 vote
0 answers
64 views

I'm trying to upgrade my Flask project from using SQLAlchemy 1.3 to 2.0. I'm following the guidance described here (https://docs.sqlalchemy.org/en/20/changelog/migration_20.html) I've gone through all ...
Ralfeus's user avatar
  • 825
0 votes
1 answer
207 views

Here's a minimal reproducible example. This is with python 3.11. Besides pytest, no other dependency. # minum_reproducible_example.py from typing import Literal from unittest.mock import Mock, patch ...
largehadroncollider's user avatar
1 vote
0 answers
32 views

Running docker compose -f docker-compose.local.yml run --rm django pytest ./project/app/ the following test passes perfectly, meaning patch method is being used @patch("project.app....
Nadav's user avatar
  • 634

1
2 3 4 5
73