Given a folder structure like such: dags/ **/ code.py tests/ dags/ **/ test_code.py conftest.py Where dags serves as the root of the src files, with ‘dags/a/b/c.py’ imported as ‘a.b.c’. I want to test the following function in code.py: from dag_common.connections import get_conn from utils.database import dbtypes def select_records( conn_id: str, sql: str, bindings, ): conn: ..
After update pytest to pytest-remotedata-0.3.2, my tests stop working correctly. Still have the same issue: start_time = datetime.fromtimestamp(test_method._outcome.result.start_time) AttributeError: ‘TestCaseFunction’ object has no attribute ‘start_time’ code: def finish_test(self, test_method, driver=None): test_status = "OK" try: start_time = list(test_method._outcome.result.test_started_datetime_map.values())[-1] except AttributeError: start_time = datetime.fromtimestamp(test_method._outcome.result.start_time) Any ideas how i can replace start_time = datetime.fromtimestamp(test_method._outcome.result.start_time) Source: Python-3x..
Problem I cannot get VSCode/unittest to recognize submodules (i.e., common.nested_module in the example in background) that I wrote unittests for. VSCode discovers the tests cases and executes those in test_my_module.py but complains that there is no module common.nested_module on the import statement line in test_nested_module.py (in Output: ModuleNotFoundError: No module named ‘common.nested_module’). I added print(sys.path) ..
I’m trying to test an api mock call using from unittest.mock import patch. I keep getting an AttributError when I include .json() in my function’s response return (i.e. return response.json()). When I exclude the .json() in my return statement, the test passes. I’m pretty new to testing and I can’t figure out how to get ..
I need to use a fixture that prepares some data inside a class that will be used to mock a third party library. Right now I have the equivalent to this: @pytest.fixture(scope="session") def file(tmpdir_factory): """Long process that creates a mock file.""" … return file_path I need to use this fixture inside the class constructor, something ..
Take this example, func_to_test_script.py from module import ClassA def func_to_test(): instance_b = ClassA.method_a() foo = instance_b.method_b() method_a returns an instance of class ClassB. I want to mock the calls of methods method_a and method_b, so I do @mock.patch("func_to_test_script.ClassA", ClassAMock) @mock.patch("func_to_test_script.ClassB", ClassBMock) def test_func_to_test(self): # test I can do this with ClassA (that was imported in ..
Issue I’ve been trying to use the unittest –buffer flag to suppress logs for successful tests and show them for failing tests. But it seems to show the log output regardless. Is this a quirk of the logging module? How can I get the log output only on failing tests? Is there a special config ..
I have a dummy funtion to try exceptions: def fun(n): try: if n <1: raise ValueError return 1 except: pass In my unit test I use: import unittest class TestFibonnacci(unittest.TestCase): def test_values(self): self.assertEqual(fun(1),1) self.assertRaises(ValueError, fun(-1)) However I’m unable to get an answer I actually get: An exception occurred E…. ERROR: test_values (main.TestFibonnacci) Traceback (most recent ..
Firstly, thank you for reading this post. Hopefully, there is an answer out there in the ether. I am using unitest and coding rooms to deliver programming courses for users. I am setting up unitest but getting errors. One of which confuses me is an EOF error which is corresponding to an input command. The ..
Can someone help me to unit test this line of code? from datetime import datetime, timedelta, timezone def get_timestamp_plus_100_year(): return int((datetime.now(timezone.utc) + timedelta(days=100 * 365)).timestamp()) I try this, but i dont know how to assigns the values: @patch("src.shared.utils.timedelta") @patch("src.shared.utils.datetime") def test_get_timestamp_now_plus_100_years(self, mock_datetime, mock_timedelta): mock_datetime.now.return_value = 2021-09-14 15:54:25.284087+00:00 mock_timedelta.return_value = 36500 days, 0:00:00 self.assertEqual( get_timestamp_plus_100_year(), int( ..