python-unittest

Python unittest assert expection as a parameter

Python unittest assert expection as a parameter Question: How to assert called function which gets exception as a parameter? In my code: def mainFunc: # … raise ValueError(‘valueError’) # … except Exception as e: myFunc(e) In the test: from unittest.mock import patch # … @patch(‘main.myFunc’) def test(mock): mainFunc() mock.assert_called_with(ValueError(‘valueError’)) And I got: AssertionError: expected call …

Total answers: 2

Python unittest – assert called with is not working

Python unittest – assert called with is not working Question: i do a gitlab api call to a put_request and for my test I want to mock this call and assert if this call was called with the specific input. The problem is I do two put requests in my question with different input. This …

Total answers: 1

Python unittest that at least one exception is raised

Python unittest that at least one exception is raised Question: Is there a way to get unittest standard library to check for multiple exceptions? Obviously assertRaises works for a single exception: How do you test that a Python function throws an exception? But I want to test whether at least one error is raised. This …

Total answers: 1

assertEqual vs assertSetEqulal in unittest

assertEqual vs assertSetEqulal in unittest Question: Is there a difference between assertEquals and assertSetEqual in the python unittest.TestCase for assertion of sets or frozensets? And if there is not, why are there assertSetEqual? also for this situation we can use assertCountEqual and assertSequenceEqual! . . . self.assertEqual({1, 2, 3}, {1, 2, 3}) self.assertSetEqual({1, 2, 3}, {1, 2, 3}) . . …

Total answers: 1

using testing.assert_series_equal when series are not in the same order

using testing.assert_series_equal when series are not in the same order Question: I have two series that are equal but in different order. data1 = np.array([‘1′,’2′,’3′,’4′,’5′,’6’]) data2=np.array([‘6′,’2′,’4′,’3′,’1′,’5′]) sr1 = pd.Series(data1) sr2=pd.Series(data2) the two series are outputs of different functions and I’m testing if they are equal: pd.testing.assert_series_equal(sr1,sr2,check_names=False) This is failing of course because the two series …

Total answers: 2

Mocking os.path.exists and os.makedirs returning AssertionError

Mocking os.path.exists and os.makedirs returning AssertionError Question: I have a function like below. # in retrieve_data.py import os def create_output_csv_file_path_and_name(output_folder=’outputs’) -> str: """ Creates an output folder in the project root if it doesn’t already exist. Then returns the path and name of the output CSV file, which will be used to write the data. …

Total answers: 1

AssertionError – Creating my own python library and I am getting an assertion error

AssertionError – Creating my own python library and I am getting an assertion error Question: I am coding an encryption library that allows you generate either symmetric or asymmetric key/key pair and use it within Either of these 4 classes: TextEncA, TextEncS, ImageEncA and ImageEncS. The code looks to be syntactically correct however while testing …

Total answers: 1