mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-31 09:44:59 +00:00
![]() # Context: USER: how can i move the patch to setUp so that it is active for all tests? ASSISTANT: To move the patch to the `setUp` method and make it active for all tests, you can use the `patch` as a context manager in the `setUp` method and store the mock object as an instance variable. Then, in the `tearDown` method, you can stop the patch. Here's how to do it: ```python tests/test_main.py <<<<<<< ORIGINAL def setUp(self): os.environ["OPENAI_API_KEY"] = "deadbeef" self.original_cwd = os.getcwd() self.tempdir = tempfile.mkdtemp() os.chdir(self.tempdir) def tearDown(self): os.chdir(self.original_cwd) shutil.rmtree(self.tempdir) ======= def setUp(self): os.environ["OPENAI_API_KEY"] = "deadbeef" self.original_cwd = os.getcwd() self.tempdir = tempfile.mkdtemp() os.chdir(self.tempdir) self.patcher = patch("aider.main.Coder.check_model_availability") self.mock_check = self.patcher.start() self.mock_check.return_value = True def tearDown(self): os.chdir(self.original_cwd) shutil.rmtree(self.tempdir) self.patcher.stop() >>>>>>> UPDATED ``` Now the patch is active for all tests, and you can remove the `with` statement from the `test_main_with_empty_dir_no_files_on_command` method: ```python tests/test_main.py <<<<<<< ORIGINAL def test_main_with_empty_dir_no_files_on_command(self): with patch("aider.main.Coder.check_model_availability") as mock_check: mock_check.return_value = True pipe_input = create_input(StringIO("")) main([], input=pipe_input, output=DummyOutput()) pipe_input.close() ======= def test_main_with_empty_dir_no_files_on_command(self): pipe_input = create_input(StringIO("")) main([], input=pipe_input, output=DummyOutput()) pipe_input.close() >>>>>>> UPDATED ``` |
||
---|---|---|
.. | ||
__init__.py | ||
test_coder.py | ||
test_commands.py | ||
test_io.py | ||
test_main.py | ||
test_repomap.py | ||
test_utils.py |