def test_shedPrivilegesError(self):
        """
        An unexpected L{OSError} when calling
        L{twisted.scripts._twistd_unix.shedPrivileges}
        terminates the process via L{SystemExit}.
        """
        def switchUIDFail(uid, gid, euid):
            raise OSError(errno.EBADF, "fake")

        runner = UnixApplicationRunner({})
        self.patch(_twistd_unix, 'switchUID', switchUIDFail)
        exc = self.assertRaises(SystemExit, runner.shedPrivileges, 35,
                                200, None)
        self.assertEqual(exc.code, 1)

        An unexpected L{OSError} when calling
        L{twisted.scripts._twistd_unix.shedPrivileges}
        terminates the process via L{SystemExit}.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py