python-unittest Questions
3
Solved
I'm asking how to mock a class property in a unit test using Python 3. I've tried the following, which makes sense for me following the docs, but it doesn't work:
foo.py:
class Foo():
@property
...
Pronto asked 9/3, 2017 at 20:8
2
I've got a simple FastAPI application and I'm trying to create tests with pytest for it.
My goal is to test how app behaves in case of different errors.
I've got a simple healthcheck route in my ...
Knoxville asked 25/3, 2020 at 17:31
3
Solved
This question gives the order assertEqual(expected, actual), albeit for the unittest package.
But Pycharm, with pytest, prints out "Expected:..." and "Actual..." based on the order actual==expect...
Candida asked 6/12, 2018 at 12:11
3
I am trying to write unittests for some of the tasks built with Airflow TaskFlow API. I tried multiple approaches for example, by creating a dagrun or only running the task function but nothing is ...
Abate asked 13/7, 2022 at 22:52
5
I have a simple directory structure:
proj/
src/
__init__.py
foo.py
bar.py
test/
__init__.py
test_foo.py
test_foo.py
import unittest
import sys
sys.path.append('../src')
from src import f...
Emeliaemelin asked 21/10, 2021 at 20:31
2
Solved
I have the following:
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
retry_strategy = Retry(
total=3,
status_forcelist=[429, 500, 502, 503, 504]...
Amyl asked 5/3, 2021 at 18:17
5
Solved
I am writing some unittests in python that are testing if I receive an integer. However sometimes this integer can be off by 1 or 2 and I don't really care. Essentially I want to be able to assert ...
Alkalize asked 24/10, 2014 at 0:42
2
Solved
I have a fixture that returns a value like this:
import pytest
@pytest.yield_fixture(scope="module")
def oneTimeSetUp(browser):
print("Running one time setUp")
if browser == 'firefox':
driver ...
Sarco asked 11/6, 2016 at 5:39
3
Solved
I'm trying to setup the target under test in @pytest.fixture and use it in all my tests in the module. I'm able to patch the test correctly, but after I add the @pytest.fixture to return the mock o...
Wilmawilmar asked 26/11, 2019 at 6:47
3
Solved
New to unittest and Python in general, came across example in a tutorial introduction to unit testing wherein a with statement is used to catch a ValueError.
The script being tested (invoice_calc...
Unreel asked 16/12, 2015 at 23:31
3
I have a test case in which in the setUp, I create an object for which I want to mock the function uuid4 in the module uuid.
TEST_UUIDS = ['uuid_{}'.format(i) for i in range(10000)]
UUID_POOL = i...
Loidaloin asked 6/6, 2017 at 16:56
4
What is the difference between setUp() and setUpClass() in the Python unittest framework? Why would setup be handled in one method over the other?
I want to understand what part of setup is done i...
Eustoliaeutectic asked 15/5, 2014 at 1:4
1
I have a django app with some unittests. I want to run\debug them in VScode v.1.59.1.
My ./vscode/settings.json looks like this:
{
"python.testing.unittestArgs": [
"-v",
&quo...
Cordeelia asked 31/8, 2021 at 10:30
0
Very similar problem described in another question and have good answer, but didn't help to solve the problem.
I wrote Scraper class which support async context manager. COUNT_OF_TESTS is defining ...
Perspex asked 25/5, 2023 at 15:38
3
Solved
I would like to exclude a list (about 5 items) of tests with py.test.
I would like to give this list to py.test via the command line.
I would like to avoid to modify the source.
How to do that?
...
Grogram asked 7/12, 2017 at 9:17
2
I'm trying to use assert_called_once_with from unittest.mock https://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock.assert_called_once_with
But I want to check if 2 instances of ob...
Cheongsam asked 23/11, 2021 at 20:31
3
Solved
I have a python file a.py which contains two classes A and B.
class A(object):
def method_a(self):
return "Class A method a"
class B(object):
def method_b(self):
a = A()
print a.method_a()
...
Goff asked 5/7, 2016 at 8:48
8
Solved
How can individual unit tests be temporarily disabled when using the unittest module in Python?
Fourwheeler asked 14/1, 2010 at 18:26
1
I wrote a unit test for main_function and asserted that it calls the function get_things inside it with an instance of a class, mocked with patch as a parameter:
@patch("get_something")
@patch("My...
Zincograph asked 12/4, 2018 at 13:57
2
This one really is stumping me. When I set an API key as an environment variable and then try to run a test with unittest that uses this API key, the test cannot access the API key. I don't want to...
Deanery asked 28/6, 2020 at 1:41
2
Solved
I am new to Python development, I am writing test cases using pytest where I need to mock some behavior. Googling best mocking library for pytest, has only confused me. I have seen unittest.mock, m...
Mccurry asked 28/1, 2022 at 4:58
6
Solved
We have numpy.testing.assert_array_equal to assert that two arrays are equal.
But what is the best way to do numpy.testing.assert_array_not_equal, that is, to make sure that two arrays are NOT equ...
Isopiestic asked 21/7, 2016 at 13:46
3
py.test documentations says that I should add capsys parameter to my test methods but in my case this doesn't seem to be possible.
class testAll(unittest.TestCase):
def setUp(self):
self.cwd = ...
Westernize asked 16/4, 2013 at 14:14
3
Solved
I am trying to create my first automated test suite with unittest for the first time.
However, when I try to execute my test suite, unittest throws the following exception:
Traceback (most recent...
Saltine asked 14/3, 2017 at 16:7
1
According to the documentation for unittest.TestLoader.discover:
discover(start_dir, pattern=’test*.py’, top_level_dir=None)
... All test modules must be importable from the top level of the
...
Sileas asked 24/9, 2017 at 12:22
© 2022 - 2025 — McMap. All rights reserved.