From: Aviskar KC Date: Thu, 20 Jun 2019 02:07:58 +0000 (+0545) Subject: Use mock.patch as context manager rather than as decorators X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a0db9ac7d960b2bcb25a94e0487345547590dcb3;p=thirdparty%2Fsqlalchemy%2Falembic.git Use mock.patch as context manager rather than as decorators --- 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, + )