fix some standalone-script running issues:
* standalone can run standalone tests * exception handling is more careful with assuming valid filenames * bits here and there --HG-- branch : trunk
This commit is contained in:
		
							parent
							
								
									6495007aba
								
							
						
					
					
						commit
						a42d9eb9f6
					
				|  | @ -6,8 +6,8 @@ import zlib | |||
| import base64 | ||||
| import sys | ||||
| 
 | ||||
| def main(pydir, outfile, infile): | ||||
|     os.chdir(os.path.dirname(str(pydir))) | ||||
| def main(pybasedir, outfile, infile): | ||||
|     os.chdir(str(pybasedir)) | ||||
|     outfile = str(outfile) | ||||
|     infile = str(infile) | ||||
|     files = [] | ||||
|  | @ -37,7 +37,7 @@ def main(pydir, outfile, infile): | |||
| 
 | ||||
| if __name__=="__main__": | ||||
|     dn = os.path.dirname | ||||
|     pydir = os.path.join(dn(dn(os.path.abspath(__file__))), 'py') | ||||
|     pybasedir = dn(dn(os.path.abspath(__file__))) | ||||
|     outfile = os.path.join(dn(__file__), "py.test") | ||||
|     infile = outfile+"-in" | ||||
|     main(pydir, outfile, infile) | ||||
|     main(pybasedir, outfile, infile) | ||||
|  |  | |||
|  | @ -2,6 +2,8 @@ import py, os, sys | |||
| import generate_standalone_pytest | ||||
| import subprocess | ||||
| mydir = py.path.local(__file__).dirpath() | ||||
| pybasedir = mydir.join("..") | ||||
| assert pybasedir.join("py").check() | ||||
| 
 | ||||
| def pytest_funcarg__standalone(request): | ||||
|     return request.cached_setup(scope="module", setup=lambda: Standalone(request)) | ||||
|  | @ -11,7 +13,7 @@ class Standalone: | |||
|         self.testdir = request.getfuncargvalue("testdir") | ||||
|         infile = mydir.join("py.test-in") | ||||
|         self.script = self.testdir.tmpdir.join("mypytest") | ||||
|         generate_standalone_pytest.main(pydir=os.path.dirname(py.__file__), | ||||
|         generate_standalone_pytest.main(pybasedir=pybasedir, | ||||
|             infile=infile, outfile=self.script) | ||||
| 
 | ||||
|     def run(self, anypython, testdir, *args): | ||||
|  | @ -34,6 +36,6 @@ def test_rundist(testdir, standalone): | |||
|     """) | ||||
|     result = standalone.run(sys.executable, testdir, '-n', '3') | ||||
|     assert result.ret == 0 | ||||
|     result.fnmatch_lines([ | ||||
|     result.stdout.fnmatch_lines([ | ||||
|         "*1 passed*" | ||||
|     ]) | ||||
|  |  | |||
|  | @ -537,8 +537,9 @@ class FormattedExcinfo(object): | |||
|         else:  | ||||
|             if self.style == "short": | ||||
|                 line = source[line_index].lstrip() | ||||
|                 trybasename = getattr(entry.path, 'basename', entry.path) | ||||
|                 lines.append('  File "%s", line %d, in %s' % ( | ||||
|                     entry.path.basename, entry.lineno+1, entry.name)) | ||||
|                     trybasename, entry.lineno+1, entry.name)) | ||||
|                 lines.append("    " + line)  | ||||
|             if excinfo:  | ||||
|                 lines.extend(self.get_exconly(excinfo, indent=4)) | ||||
|  |  | |||
|  | @ -1,5 +1,7 @@ | |||
| from py.plugin.pytest_doctest import DoctestModule, DoctestTextfile | ||||
| 
 | ||||
| pytest_plugins = ["pytest_doctest"] | ||||
| 
 | ||||
| class TestDoctests: | ||||
|   | ||||
|     def test_collect_testtextfile(self, testdir): | ||||
|  | @ -12,14 +14,15 @@ class TestDoctests: | |||
|         """) | ||||
|         for x in (testdir.tmpdir, checkfile):  | ||||
|             #print "checking that %s returns custom items" % (x,)  | ||||
|             items, reprec = testdir.inline_genitems(x) | ||||
|             items, reprec = testdir.inline_genitems(x, '-p', 'doctest') | ||||
|             assert len(items) == 1 | ||||
|             assert isinstance(items[0], DoctestTextfile) | ||||
| 
 | ||||
|     def test_collect_module(self, testdir): | ||||
|         path = testdir.makepyfile(whatever="#") | ||||
|         for p in (path, testdir.tmpdir):  | ||||
|             items, reprec = testdir.inline_genitems(p, '--doctest-modules') | ||||
|             items, reprec = testdir.inline_genitems(p, '-p', 'doctest',  | ||||
|                 '--doctest-modules') | ||||
|             assert len(items) == 1 | ||||
|             assert isinstance(items[0], DoctestModule) | ||||
| 
 | ||||
|  | @ -29,7 +32,7 @@ class TestDoctests: | |||
|             >>> x == 1 | ||||
|             False | ||||
|         """) | ||||
|         reprec = testdir.inline_run(p) | ||||
|         reprec = testdir.inline_run(p, '-p', 'doctest') | ||||
|         reprec.assertoutcome(failed=1) | ||||
| 
 | ||||
|     def test_doctest_unexpected_exception(self, testdir): | ||||
|  | @ -41,7 +44,7 @@ class TestDoctests: | |||
|             >>> x | ||||
|             2 | ||||
|         """) | ||||
|         reprec = testdir.inline_run(p) | ||||
|         reprec = testdir.inline_run(p, '-p', 'doctest') | ||||
|         call = reprec.getcall("pytest_runtest_logreport") | ||||
|         assert call.report.failed | ||||
|         assert call.report.longrepr  | ||||
|  | @ -60,7 +63,7 @@ class TestDoctests: | |||
| 
 | ||||
|             ''' | ||||
|         """) | ||||
|         reprec = testdir.inline_run(p, "--doctest-modules") | ||||
|         reprec = testdir.inline_run(p, '-p', 'doctest', "--doctest-modules") | ||||
|         reprec.assertoutcome(failed=1)  | ||||
| 
 | ||||
|     def test_doctestmodule_external(self, testdir): | ||||
|  | @ -73,7 +76,7 @@ class TestDoctests: | |||
|                     2 | ||||
|                 ''' | ||||
|         """) | ||||
|         result = testdir.runpytest(p, "--doctest-modules") | ||||
|         result = testdir.runpytest(p, '-p', 'doctest', "--doctest-modules") | ||||
|         result.stdout.fnmatch_lines([ | ||||
|             '004 *>>> i = 0', | ||||
|             '005 *>>> i + 1', | ||||
|  | @ -91,7 +94,7 @@ class TestDoctests: | |||
|             >>> i + 1 | ||||
|             2 | ||||
|         """) | ||||
|         result = testdir.runpytest(p) | ||||
|         result = testdir.runpytest(p, '-p', 'doctest') | ||||
|         result.stdout.fnmatch_lines([ | ||||
|             '001 >>> i = 0', | ||||
|             '002 >>> i + 1', | ||||
|  |  | |||
|  | @ -5,9 +5,9 @@ def test_version(testdir): | |||
|     assert py.version == py.__version__  | ||||
|     result = testdir.runpytest("--version") | ||||
|     assert result.ret == 0 | ||||
|     p = py.path.local(py.__file__).dirpath() | ||||
|     #p = py.path.local(py.__file__).dirpath() | ||||
|     assert result.stderr.fnmatch_lines([ | ||||
|         '*py.test*%s*imported from*%s*' % (py.version, p) | ||||
|         '*py.test*%s*imported from*' % (py.version, ) | ||||
|     ]) | ||||
| 
 | ||||
| def test_helpconfig(testdir): | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue