def test_run_load_list(self): if fixtures is None: self.skipTest("Need fixtures") self.useFixture(SampleTestFixture()) out = StringIO() # We load two tests - one that exists and one that doesn't, and we # should get the one that exists and neither the one that doesn't nor # the unmentioned one that does. tempdir = self.useFixture(fixtures.TempDir()) tempname = tempdir.path + '/tests.list' f = open(tempname, 'wb') try: f.write( _b(""" testtools.runexample.TestFoo.test_bar testtools.runexample.missingtest """)) finally: f.close() run.main([ 'prog', '-l', '--load-list', tempname, 'testtools.runexample.test_suite' ], out) self.assertEqual("""testtools.runexample.TestFoo.test_bar """, out.getvalue())
def test_run_list(self): self.useFixture(SampleTestFixture()) out = StringIO() run.main(['prog', '-l', 'testtools.runexample.test_suite'], out) self.assertEqual("""testtools.runexample.TestFoo.test_bar testtools.runexample.TestFoo.test_quux """, out.getvalue())
def test_load_list_preserves_custom_suites(self): if testresources is None: self.skipTest("Need testresources") self.useFixture(SampleResourcedFixture()) # We load two tests, not loading one. Both share a resource, so we # should see just one resource setup occur. tempdir = self.useFixture(fixtures.TempDir()) tempname = tempdir.path + '/tests.list' f = open(tempname, 'wb') try: f.write( _b(""" testtools.resourceexample.TestFoo.test_bar testtools.resourceexample.TestFoo.test_foo """)) finally: f.close() stdout = self.useFixture(fixtures.StringStream('stdout')) with fixtures.MonkeyPatch('sys.stdout', stdout.stream): try: run.main([ 'prog', '--load-list', tempname, 'testtools.resourceexample.test_suite' ], stdout.stream) except SystemExit: # Evil resides in TestProgram. pass out = stdout.getDetails()['stdout'].as_text() self.assertEqual(1, out.count('Setting up Printer'), "%r" % out)
def test_load_list_preserves_custom_suites(self): if testresources is None: self.skipTest("Need testresources") self.useFixture(SampleResourcedFixture()) # We load two tests, not loading one. Both share a resource, so we # should see just one resource setup occur. tempdir = self.useFixture(fixtures.TempDir()) tempname = tempdir.path + '/tests.list' f = open(tempname, 'wb') try: f.write(_b(""" testtools.resourceexample.TestFoo.test_bar testtools.resourceexample.TestFoo.test_foo """)) finally: f.close() stdout = self.useFixture(fixtures.StringStream('stdout')) with fixtures.MonkeyPatch('sys.stdout', stdout.stream): try: run.main(['prog', '--load-list', tempname, 'testtools.resourceexample.test_suite'], stdout.stream) except SystemExit: # Evil resides in TestProgram. pass out = stdout.getDetails()['stdout'].as_text() self.assertEqual(1, out.count('Setting up Printer'), "%r" % out)
def test_run_load_list(self): self.useFixture(SampleTestFixture()) out = StringIO() # We load two tests - one that exists and one that doesn't, and we # should get the one that exists and neither the one that doesn't nor # the unmentioned one that does. tempdir = self.useFixture(fixtures.TempDir()) tempname = tempdir.path + '/tests.list' f = open(tempname, 'wb') try: f.write( _b(""" testtools.runexample.TestFoo.test_bar testtools.runexample.missingtest """)) finally: f.close() try: run.main([ 'prog', '-l', '--load-list', tempname, 'testtools.runexample.test_suite' ], out) except SystemExit: exc_info = sys.exc_info() raise AssertionError("-l --load-list tried to exit. %r" % exc_info[1]) self.assertEqual("""testtools.runexample.TestFoo.test_bar """, out.getvalue())
def call_subunit_run(test_id, pretty, subunit): env = copy.deepcopy(os.environ) cmd_save_results = ['stestr', 'load', '--subunit'] if not os.path.isdir('.stestr'): commands.init_command() if pretty: # Use subunit run module cmd = ['python', '-m', 'subunit.run', test_id] ps = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE) # Save subunit results via testr pfile = subprocess.Popen(cmd_save_results, env=env, stdin=ps.stdout, stdout=subprocess.PIPE) ps.stdout.close() # Transform output via subunit-trace proc = subprocess.Popen(['subunit-trace', '--no-failure-debug', '-f'], env=env, stdin=pfile.stdout) pfile.stdout.close() proc.communicate() return proc.returncode elif subunit: sstdout = io.BytesIO() subunit_run.main([sys.argv[0], test_id], sstdout) pfile = subprocess.Popen(cmd_save_results, env=env, stdin=subprocess.PIPE) pfile.communicate(input=sstdout.getvalue()) else: testtools_run.main([sys.argv[0], test_id], sys.stdout)
def test_run_load_list(self): self.useFixture(SampleTestFixture()) out = StringIO() # We load two tests - one that exists and one that doesn't, and we # should get the one that exists and neither the one that doesn't nor # the unmentioned one that does. tempdir = self.useFixture(fixtures.TempDir()) tempname = tempdir.path + '/tests.list' f = open(tempname, 'wb') try: f.write(_b(""" testtools.runexample.TestFoo.test_bar testtools.runexample.missingtest """)) finally: f.close() try: run.main(['prog', '-l', '--load-list', tempname, 'testtools.runexample.test_suite'], out) except SystemExit: exc_info = sys.exc_info() raise AssertionError( "-l --load-list tried to exit. %r" % exc_info[1]) self.assertEqual("""testtools.runexample.TestFoo.test_bar """, out.getvalue())
def test_run_list(self): if fixtures is None: self.skipTest("Need fixtures") package = self.useFixture(SampleTestFixture()) out = StringIO() run.main(['prog', '-l', 'testtools.runexample.test_suite'], out) self.assertEqual("""testtools.runexample.TestFoo.test_bar testtools.runexample.TestFoo.test_quux """, out.getvalue())
def test_run_list(self): if fixtures is None: self.skipTest("Need fixtures") package = self.useFixture(SampleTestFixture()) out = StringIO() run.main(['prog', '-l', 'testtools.runexample.test_suite'], out) self.assertEqual( """testtools.runexample.TestFoo.test_bar testtools.runexample.TestFoo.test_quux """, out.getvalue())
def test_run_list(self): self.useFixture(SampleTestFixture()) out = StringIO() try: run.main(['prog', '-l', 'testtools.runexample.test_suite'], out) except SystemExit: exc_info = sys.exc_info() raise AssertionError("-l tried to exit. %r" % exc_info[1]) self.assertEqual("""testtools.runexample.TestFoo.test_bar testtools.runexample.TestFoo.test_quux """, out.getvalue())
def call_subunit_run(test_id, pretty, subunit): if pretty: env = copy.deepcopy(os.environ) cmd = ["python", "-m", "subunit.run", test_id] ps = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE) proc = subprocess.Popen(["subunit-trace", "--no-failure-debug", "-f"], env=env, stdin=ps.stdout) ps.stdout.close() proc.communicate() return proc.returncode elif subunit: subunit_run.main([sys.argv[0], test_id], sys.stdout) else: testtools_run.main([sys.argv[0], test_id], sys.stdout)
def call_subunit_run(test_id, pretty, subunit): if pretty: env = copy.deepcopy(os.environ) cmd = ['python', '-m', 'subunit.run', test_id] ps = subprocess.Popen(cmd, env=env, stdout=subprocess.PIPE) proc = subprocess.Popen(['subunit-trace', '--no-failure-debug', '-f'], env=env, stdin=ps.stdout) ps.stdout.close() proc.communicate() return proc.returncode elif subunit: subunit_run.main([sys.argv[0], test_id], sys.stdout) else: testtools_run.main([sys.argv[0], test_id], sys.stdout)
def test_run_orders_tests(self): self.useFixture(SampleTestFixture()) out = StringIO() # We load two tests - one that exists and one that doesn't, and we # should get the one that exists and neither the one that doesn't nor # the unmentioned one that does. tempdir = self.useFixture(fixtures.TempDir()) tempname = tempdir.path + '/tests.list' f = open(tempname, 'wb') try: f.write(_b(""" testtools.runexample.TestFoo.test_bar testtools.runexample.missingtest """)) finally: f.close() run.main(['prog', '-l', '--load-list', tempname, 'testtools.runexample.test_suite'], out) self.assertEqual("""testtools.runexample.TestFoo.test_bar """, out.getvalue())
def test_issue_16662(self): # unittest's discover implementation didn't handle load_tests on # packages. That is fixed pending commit, but we want to offer it # to all testtools users regardless of Python version. # See http://bugs.python.org/issue16662 pkg = self.useFixture(SampleLoadTestsPackage()) out = StringIO() self.assertEqual(None, run.main( ['prog', 'discover', '-l', pkg.package.base], out)) self.assertEqual(dedent("""\ discoverexample.TestExample.test_foo fred """), out.getvalue())
def test_issue_16662(self): # unittest's discover implementation didn't handle load_tests on # packages. That is fixed pending commit, but we want to offer it # to all testtools users regardless of Python version. # See http://bugs.python.org/issue16662 pkg = self.useFixture(SampleLoadTestsPackage()) out = StringIO() self.assertEqual( None, run.main(['prog', 'discover', '-l', pkg.package.base], out)) self.assertEqual( dedent("""\ discoverexample.TestExample.test_foo fred """), out.getvalue())
def call_testtools_run(test_id): testtools_run.main([sys.argv[0], test_id], sys.stdout)