def test_runUsedDirectory(self):
        """
        L{DistTrialRunner} checks if the test directory is already locked, and
        if it is generates a name based on it.
        """

        class CountingReactorWithLock(CountingReactor):

            def spawnProcess(oself, worker, *args, **kwargs):
                oself._workers.append(worker)
                self.assertEqual(os.path.abspath(worker._logDirectory),
                                 os.path.abspath(
                                     os.path.join(workingDirectory + "-1",
                                                  str(oself.spawnCount))))
                localLock = FilesystemLock(workingDirectory + "-1.lock")
                self.assertFalse(localLock.lock())
                oself.spawnCount += 1
                worker.makeConnection(FakeTransport())
                worker._ampProtocol.run = lambda *args: succeed(None)

        newDirectory = self.mktemp()
        os.mkdir(newDirectory)
        workingDirectory = os.path.join(newDirectory, "_trial_temp")
        lock = FilesystemLock(workingDirectory + ".lock")
        lock.lock()
        self.addCleanup(lock.unlock)
        self.runner._workingDirectory = workingDirectory

        workers = []

        fakeReactor = CountingReactorWithLock(workers)
        self.addCleanup(self.reap, workers)

        suite = TrialSuite()
        for i in range(10):
            suite.addTest(TestCase())

        self.runner.run(suite, fakeReactor)

        L{DistTrialRunner} checks if the test directory is already locked, and
        if it is generates a name based on it.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/trial/_dist/test/test_disttrial.py