Skip to content
Advertisement

Tag: python-unittest

How to unittest a datetime function

file.py test.py I get an Error: TypeError: ‘>’ not supported between instances of ‘MagicMock’ and ‘int’ Is there anyway to test this function? Probably the problem is with this part of the last line: (utc_date – namespace_created_date).days Answer I could reproduce and fix. Here is a working unittest file (assuming file.py is accessible): If I use date_now.datetime.utcnow.date.return_value = datetime.datetime(2022,1,1) I

unit test of function in different directory gives AttributeError: module has no attribute

What specific syntax must be changed below in order for a unit test running in one part of a file system to successfully test a function in a class that is located in a completely different part of a file system? The test file is located at C:pathtosome-test-classestest_an_example.py The class being tested is located at C:\completely\different\path\an_example.py The problem might be

Python unittest AssertionError: 0 != []

I’m new to Python unittest and I’m trying to access this list: to do this test: I’ve created this function: But I keep getting this error: AssertionError: 0 != [] Can someone help explain what I’m doing wrong in the function please? Answer Let’s take a look at this part, the get_customer_pet_count function: First, you’re not passing it a “customer

Python Unittest Allow Multiple Possible Return Values

I’m writing a unittest that will be run on my class’s code. For one of the functions they must write, there are two possible return values that they could return and either one is okay for my purposes. I’ve been using But this doesn’t work for accepting one of two valid return values, so I’ve changed it to: Is there

Advertisement