]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph-volume/tests: fix test_exception_returns_default 47434/head
authorGuillaume Abrioux <gabrioux@redhat.com>
Wed, 3 Aug 2022 09:16:36 +0000 (11:16 +0200)
committerGuillaume Abrioux <gabrioux@redhat.com>
Wed, 3 Aug 2022 09:16:36 +0000 (11:16 +0200)
There are cases, like running tests as root user, where this test fails
because root user can always read the file content.

Signed-off-by: Guillaume Abrioux <gabrioux@redhat.com>
src/ceph-volume/ceph_volume/tests/util/test_system.py

index 763b18768b44b11209820b575abe0dc1b8d19ca2..cfaac5be747a594185d42431b8bae5bc5af842e9 100644 (file)
@@ -207,11 +207,10 @@ class TestGetFileContents(object):
         result = system.get_file_contents(interesting_file.path)
         assert result == "0\n1"
 
-    def test_exception_returns_default(self, fake_filesystem):
-        interesting_file = fake_filesystem.create_file('/tmp/fake-file', contents="0")
-        # remove read, causes IOError
-        os.chmod(interesting_file.path, 0o000)
-        result = system.get_file_contents(interesting_file.path)
+    def test_exception_returns_default(self):
+        with patch('builtins.open') as mocked_open:
+            mocked_open.side_effect = Exception()
+            result = system.get_file_contents('/tmp/fake-file')
         assert result == ''