python-unittest Questions

2

I have been using unittest.IsolatedAsyncioTestCase to test my async methods. I have been making use of setUpClass and asyncSetUp to create a fixture, and asyncTearDown to cleanup. This is all worki...
Lucubration asked 11/4, 2023 at 16:40

4

Solved

I have the following validation function in my model: @classmethod def validate_kind(cls, kind): if kind == 'test': raise ValidationError("Invalid question kind") which I am trying to test as ...
Hysterectomize asked 21/4, 2018 at 10:43

3

I installed coverage gutter extension for visual studio code but is not showing the line coverage, when I press Coverage Gutter display coverage or press the "watch" option in the footer it says "C...

3

Solved

Is there a way to run unittests in pycharm in verbose mode. I am looking for a way to see the docstring in the test functions so that i can see some info of the ran test. class KnownValues(unittes...
Sandrasandro asked 22/4, 2017 at 16:43

3

Solved

I'm testing python code (A django 3.0.5 project although I don't think it's relevant), but I can't get the functions of my mocked objects to be called. Here is my code: **myproject.mypackage.myhelp...
Aspirant asked 16/7, 2020 at 8:6

3

Solved

I've successfully used the standard python unittest framework in several projects recently, but in the last few days it fails to work as before. One issue is that it now seems to try to use pytest ...
Tantalite asked 14/7, 2023 at 14:23

6

Solved

In my test case, I assume that if two values are NaN then they are equal. What is the way to express it using unittest assertions? The two common functions presented below are not handling this cas...
Hitandrun asked 7/8, 2018 at 13:49

17

Solved

I have a test file that contains tests taking quite a lot of time (they send calculations to a cluster and wait for the result). All of these are in specific TestCase class. Since they take time an...
Syracuse asked 1/7, 2009 at 9:40

5

Solved

While running a particular unittest with pytest, it occasionally fails with this error (mentioned in the title) and from the stack trace it happens on the line choice = input().lower() when the c...
Calcium asked 18/7, 2018 at 2:52

11

I've written a python test file called scraping_test.py, with a single test class, using unittest, called TestScrapingUtils """Tests for the scraping app""" import unittest from bs4 import Beauti...
Preshrunk asked 24/12, 2017 at 12:18

3

Solved

(The following code can be run in Jupyter.) I have a class B, which uses class A, needs to be tested. class A: async def f(self): pass class B: async def f(self): a = A() x = await a.f() # ne...
Flinty asked 5/2, 2022 at 4:59

7

Solved

I want to make a stub to prevent time.sleep(..) to sleep to improve the unit test execution time. What I have is: import time as orgtime class time(orgtime): '''Stub for time.''' _sleep_speed_...
Steal asked 3/4, 2014 at 11:53

2

Solved

I'm writing tests for my Flask project, and are trying to mock my database model. The code looks something like this: import unittest.mock @unittest.mock.patch("server.models.user") def test_that...
Marinemarinelli asked 19/9, 2018 at 11:16

3

I am writing a unit test for embedded software code in python. One of the files require a specific file to exist. (e.g. "/dir_name/file_name.txt") otherwise it raises an error. Normally, this fil...
Somersomers asked 22/10, 2016 at 0:57

5

Solved

For the following code: import unittest class Test(unittest.TestCase): def test1(self): assert(True == True) if __name__ == "__main__": suite = unittest.TestSuite() suite.addTest(Test()) un...
Duplication asked 30/9, 2013 at 5:45

5

Solved

I want to understand how to @patch a function from an imported module. This is where I am so far. app/mocking.py: from app.my_module import get_user_name def test_method(): return get_user_nam...
Deglutinate asked 21/4, 2013 at 17:48

3

Solved

In my python application, I open mp3 files with relative paths from where the program was started. To keep it simple, I made a minimal reproduction of the problem I have in my project here. Basica...
Cowfish asked 19/10, 2018 at 22:5

7

Solved

I know similar questions have been asked before... But I had a quick doubt... I have been following this link: https://www.python-course.eu/python3_packages.php my code structure: my-project -- __...
Tendon asked 26/6, 2018 at 18:50

5

Solved

unittest.mock objects have an assert_not_called method available, but what I'm looking for is an assert_not_called_with. Is there anything like that? I looked on Google and didn't see anything, and...
Coyotillo asked 23/2, 2019 at 4:52

6

As part of some Python tests using the unittest framework, I need to compare two relatively short text files, where the one is a test output file and the other is a reference file. The immediate a...
Subzero asked 28/2, 2017 at 14:56

4

Solved

I am using Python's unittest module to test a script I am writing. The script contains a loop like this: // my_script.py def my_loopy_function(): aggregate_value = 0 for x in range(10): aggre...
Knowlton asked 19/12, 2014 at 17:57

4

Solved

Say I have the following Python UnitTest: import unittest def Test(unittest.TestCase): @classmethod def setUpClass(cls): # Get some resources ... if error_occurred: assert(False) @classm...
Combo asked 9/7, 2013 at 0:43

1

When calling unittest.TestCase.assertEqual() on two complex dictionaries, I get a nice diff. Is there any way to get a diff from Python 2.7's mock.Mock.assert_called_with? I'm testing calls that t...
Straub asked 7/9, 2016 at 15:37

3

Solved

I am trying to come up with a method to test a number of Jupyter notebooks. A test should run when a new notebook is implemented in a Github branch and submitted for a pull request. The tests are n...
Geniegenii asked 11/1, 2022 at 18:29

0

Decided to upgrade Python version from 3.10 to 3.11, previously we have used asynctest.TestCase which has setUp and tearDown methods and supports testing of async code. I've checked unittest.Isolat...
Corkhill asked 11/12, 2023 at 20:46

© 2022 - 2024 — McMap. All rights reserved.