def patchOpen(self):
        """
        Patch L{_options.open} so we can capture usage and prevent actual opens.
        """
        self.opened = []

        def fakeOpen(name, mode=None):
            if name == "nocanopen":
                raise IOError(None, None, name)

            self.opened.append((name, mode))
            return NotImplemented

        self.patch(_options, "openFile", fakeOpen)

        Patch L{_options.open} so we can capture usage and prevent actual opens.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/application/twist/test/test_options.py