def test_collisionProtection(self):
        """
        If tempfile.gettempdir() is used for dir, using same testfile name will
        not collide.
        """
        sub_tmpdir = tempfile.mkdtemp(dir=self.tmpdir)
        # Child setup
        # pkg/__init__.py
        fh = open(os.path.join(sub_tmpdir, '__init__.py'), 'w')
        fh.write('\n')
        fh.close()
        # pkg/target_module.py
        fh = open(os.path.join(sub_tmpdir, 'some_module.py'), 'w')
        fh.write('a = 1\n')
        fh.close()
        # pkg/test/__init__.py
        os.mkdir(os.path.join(sub_tmpdir, 'test'))
        fh = open(os.path.join(sub_tmpdir, 'test', '__init__.py'), 'w')
        fh.write('\n')
        fh.close()
        # pkg/test/test_target_module.py
        fh = open(os.path.join(sub_tmpdir, 'test', 'test_some_module.py'), 'w')
        fh.write(dedent(
            """
            import os
            import tempfile
            import unittest
            import {}.some_module
            class A(unittest.TestCase):
                def setUp(self):
                    self.tmpdir = tempfile.gettempdir()
                    self.filename = os.path.join(tempfile.gettempdir(), 'file.txt')
                def testOne(self):
                    for msg in [str(x) for x in range(100)]:
                        fh = open(self.filename, 'w')
                        fh.write(msg)
                        fh.close()
                        self.assertEqual(msg, open(self.filename).read())
                def testTwo(self):
                    for msg in [str(x) for x in range(100,200)]:
                        fh = open(self.filename, 'w')
                        fh.write(msg)
                        fh.close()
                        self.assertEqual(msg, open(self.filename).read())
            """.format(os.path.basename(sub_tmpdir))))
        fh.close()
        # Load the tests
        os.chdir(self.tmpdir)
        tests = loadTargets('.')
        self.args.processes = 2
        self.args.termcolor = False
        try:
            run(tests, self.stream, self.args)
        except __HOLE__:
            os.kill(os.getpid(), signal.SIGINT)
        os.chdir(TestProcesses.startdir)
        self.assertIn('OK', self.stream.getvalue())
dataset/ETHPy150Open CleanCut/green/green/test/test_runner.py/TestProcesses.test_collisionProtection