Skip to main content
Filter by
Sorted by
Tagged with
0 votes
1 answer
56 views

We recently upgraded from Python 3.9 to 3.14 and it appears that the default start method for multiprocessing has switched from 'fork' to 'spawn' and it is causing some tests to fail, trying to ...
rpmcnally's user avatar
  • 269
1 vote
1 answer
258 views

I'm using basedpyright for static type checking, and it fails to resolve imports from a test utility module located under the tests directory. However, unittest executes the tests without any issues. ...
usan's user avatar
  • 179
Advice
1 vote
1 replies
122 views

I have a series of unit tests that should run for two different implementations of a same “interface.” Those tests use only the methods that exist in both implementations. Since they end up identical, ...
Arseni Mourzenko's user avatar
1 vote
1 answer
163 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,708
-1 votes
1 answer
56 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
92 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,179
1 vote
1 answer
75 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
85 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
145 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,320
1 vote
0 answers
106 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
105 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
475 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
126 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
70 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
78 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
88 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
  • 346
1 vote
1 answer
275 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
52 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
  • 611
1 vote
1 answer
71 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
123 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
68 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
50 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
95 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
1 vote
2 answers
173 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
37 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
34 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,753
1 vote
1 answer
227 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
36 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
85 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
24 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
94 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
147 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
52 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
168 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,183
1 vote
1 answer
109 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
57 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
2 votes
1 answer
234 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.4k
0 votes
1 answer
247 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
55 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
116 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,503
0 votes
1 answer
88 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
68 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
55 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
152 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
80 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
190 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
70 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
327 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
39 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
0 votes
1 answer
2k views

I am trying to preform asynchronous testing for a class who perform HTTPS request using aiohttp.ClientSession. The issue I am having is that when I call async with session.get as response the ...
Yonatan Levin's user avatar

1
2 3 4 5
73