From a0db9ac7d960b2bcb25a94e0487345547590dcb3 Mon Sep 17 00:00:00 2001 From: Aviskar KC Date: Thu, 20 Jun 2019 07:52:58 +0545 Subject: [PATCH] Use mock.patch as context manager rather than as decorators --- tests/test_command.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/tests/test_command.py b/tests/test_command.py index f04b1902..933d7c8d 100644 --- a/tests/test_command.py +++ b/tests/test_command.py @@ -798,15 +798,16 @@ class CommandLineTest(TestBase): # not too long assert len(help_text) < 80 assert not commands, "Commands without help text: %s" % commands - - @mock.patch("alembic.command.os.listdir", return_value = ["file1", "file2"]) - @mock.patch("alembic.command.os.access", return_value = True) - def test_init_file_exists_and_is_not_empty(self, mocked_listdir, mocked_access): - directory = "alembic" - assert_raises_message( - util.CommandError, - "Directory %s already exists and is not empty" % directory, - command.init, - self.cfg, - directory = directory - ) + + def test_init_file_exists_and_is_not_empty(self): + with mock.patch( + "alembic.command.os.listdir", return_value=["file1", "file2"] + ), mock.patch("alembic.command.os.access", return_value=True): + directory = "alembic" + assert_raises_message( + util.CommandError, + "Directory %s already exists and is not empty" % directory, + command.init, + self.cfg, + directory=directory, + ) -- 2.47.2