def _setUID(self, wantedUser, wantedUid, wantedGroup, wantedGid):
        """
        Common code for tests which try to pass the the UID to
        L{UnixApplicationRunner}.
        """
        patchUserDatabase(self.patch, wantedUser, wantedUid, wantedGroup,
                          wantedGid)

        def initgroups(uid, gid):
            self.assertEqual(uid, wantedUid)
            self.assertEqual(gid, wantedGid)

        def setuid(uid):
            self.assertEqual(uid, wantedUid)

        def setgid(gid):
            self.assertEqual(gid, wantedGid)

        self.patch(util, "initgroups", initgroups)
        self.patch(os, "setuid", setuid)
        self.patch(os, "setgid", setgid)

        options = twistd.ServerOptions()
        options.parseOptions([
            '--nodaemon',
            '--uid', str(wantedUid)])
        application = service.Application("test_setupEnvironment")
        self.runner = UnixApplicationRunner(options)
        runner = UnixApplicationRunner(options)
        runner.startApplication(application)

        Common code for tests which try to pass the the UID to
        L{UnixApplicationRunner}.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/test/test_twistd.py