Skip to content

Bug when trying to Stub os.path.exists #7

@sk-

Description

@sk-

Please see the test below. The first test fails with an infinite recursion and the second works just great.

import os
from unittest import TestCase

from ludibrio import Stub, any

class TestStubReplacesStdlib(TestCase):
    def test_os_path_exist_bug(self):
        with Stub() as exists:
            from os.path import exists
            exists(any()) >> True
        self.assertTrue(os.path.exists('/path/to/inexistent/file'))
        exists.restore_import()

    def test_stub_replacement_success(self):
        with Stub() as getsize:
            from os.path import getsize
            getsize(any()) >> 1
        self.assertEquals(os.path.getsize('/path/to/inexistent/file'), 1)
        getsize.restore_import()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions