All Questions
128
questions
1
vote
2
answers
64
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
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
vote
1
answer
50
views
statically inspect a python test suite
I have a (unittest-based) test suite for my python project.
Here I have my test classes, with my test methods, etc...
In (some of my) tests I call a function to initialize the scenarios of the tests. ...
1
vote
1
answer
36
views
Python ModuleNotFoundError when running tests
I have a Python program that runs correctly as expected, but for some reason I am not able to execute the tests.
In the folder hierarchy, tests is a sibling folder of src and the error I got when ...
0
votes
2
answers
202
views
Getting module names from unittest tests in python
Is there a way to get test module names programmatically, from a test suite, when using python unittest?
Python unittest.loader.TestLoader has a discover method that returns all test modules but I can'...
3
votes
1
answer
565
views
Python testing assertions (unittest, playwright)
so im new to testing and have been learning python/playwright testing for a couple of weeks now.
I've got to assertions and have found multiple ways to write them, so this might sound like a stupid ...
2
votes
1
answer
616
views
ModuleNotFoundError when trying to debug a test
I am trying to debug a failing test method in VS Code but when I use the Debug Test action from the Testing sidebar or the context menu for the test method, it fails with the following error (found in ...
0
votes
0
answers
221
views
Unit testing private methods
Several questions, such as Should I test private methods or only public ones? seem to encourage testing private methods through the public interfaces because:
You test the private methods, by writing ...
0
votes
0
answers
32
views
How to fail unittest test suite even when all test cases pass
I am using python unit test framework to run automated test cases. Currently I want to have the ability to fail the test suite if a condition is not met even if all the test cases pass. I want the ...
0
votes
0
answers
71
views
Encountering an error when running mut.py: "mut.py: error: unrecognized arguments"
When i try to run mut.py i encounter this error
C:\Pprogs>mut.py --dcmotor_pid_control --dcmotor_tests -m
usage: mut.py [-h] [--version] [--target TARGET [TARGET ...]] [--unit-test UNIT_TEST [...
0
votes
1
answer
648
views
How to mock requests.Session.get using unittest module?
I want to mock app.requests.Session.get from test_app.py to return a mocked requests.Response object with a 404 status_code to generate an InvalidPlayerIdException.
However, no exception is raised as ...
1
vote
0
answers
2k
views
ModuleNotFoundError: No module named [duplicate]
I have a project arranged like so:
Project
└── test
├── main.py
│
└── x.py
│
└── y.py
I try to run the tests by executing python -m test.main.py from the project directory, ...
0
votes
1
answer
729
views
Mocking variable and replacing it with object
I'd like to test this piece of code:
modify: UserModifyPort = _ports_.user_modify_port
@_app_.route(f"/user", methods=["POST"])
@headers_check({"Accept": "...
0
votes
2
answers
603
views
Python unit testing with unittest module
This is how I wrote the code to start a test with the unittest module but it is returning as 0 tests. Is the return making any problems? (I am able to share the complete code but it is long). Posting ...
1
vote
1
answer
744
views
Why is Python assertEqual telling me I'm missing the second argument in this unittest?
I'm currently testing the construction of some objects in Python, and I simply can't get past this infuriating error. Here is my code:
from unittest import TestCase
class TestEquals(TestCase):
...