| 1 |
import py |
| 2 |
import sys |
| 3 |
import subprocess |
| 4 |
|
| 5 |
innertest = py.path.local(__file__).dirpath('conftest1_innertest.py') |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
def subproc_run(*args): |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
cur_dir = str(py.path.local(__file__).dirpath()) |
| 14 |
test_all = py.path.local(__file__).dirpath('..', '..', '..', 'test_all.py') |
| 15 |
args = [sys.executable, str(test_all), "-v"] + map(str, args) |
| 16 |
print '=========>', args |
| 17 |
passed, failed = [], [] |
| 18 |
popen = subprocess.Popen(args, stdout=subprocess.PIPE, cwd=cur_dir) |
| 19 |
output, _ = popen.communicate() |
| 20 |
|
| 21 |
for line in output.splitlines(False): |
| 22 |
if line.startswith('conftest1_innertest.py'): |
| 23 |
line = line[len('conftest1_innertest.py'):] |
| 24 |
testname, result = line.lstrip(':').strip().split() |
| 25 |
if result == 'PASSED': |
| 26 |
passed.append(testname) |
| 27 |
elif result == 'FAILED': |
| 28 |
failed.append(testname) |
| 29 |
else: |
| 30 |
assert False, "unexpected output line: %r" % (line,) |
| 31 |
return passed, failed |
| 32 |
|
| 33 |
|
| 34 |
class TestPyPyTests: |
| 35 |
def test_selection_by_keyword_interp(self): |
| 36 |
passed, failed = subproc_run("-m", "interplevel", innertest) |
| 37 |
assert len(passed) == 2, len(passed) |
| 38 |
assert not failed |
| 39 |
assert "test_something" in passed[0] |
| 40 |
assert "test_method" in passed[1] |
| 41 |
|
| 42 |
def test_selection_by_keyword_app(self): |
| 43 |
passed, failed = subproc_run("-m", "applevel -docstring", innertest) |
| 44 |
assert len(passed) == 2 |
| 45 |
assert len(failed) == 1 |
| 46 |
assert "test_method_app" in passed[0] |
| 47 |
|
| 48 |
def test_docstring_in_methods(self): |
| 49 |
passed, failed = subproc_run("-k", "AppTestSomething and test_code_in_docstring", |
| 50 |
innertest) |
| 51 |
assert len(passed) == 1 |
| 52 |
assert len(failed) == 1 |
| 53 |
assert "test_code_in_docstring_ignored" in passed[0] |
| 54 |
assert "test_code_in_docstring_failing" in failed[0] |
| 55 |
|
| 56 |
@py.test.mark.xfail(reason='fails on buildslave') |
| 57 |
def test_docstring_runappdirect(self): |
| 58 |
passed, failed = subproc_run(innertest, |
| 59 |
'-k', 'test_code_in_docstring', |
| 60 |
'--runappdirect') |
| 61 |
assert len(passed) == 1 |
| 62 |
assert len(failed) == 2 |
| 63 |
assert "test_code_in_docstring_ignored" in passed[0] |
| 64 |
assert "app_test_code_in_docstring_failing" in failed[0] |
| 65 |
assert "test_code_in_docstring_failing" in failed[1] |
| 66 |
|
| 67 |
@py.test.mark.xfail(reason='fails on buildslave') |
| 68 |
def test_raises_inside_closure(self): |
| 69 |
passed, failed = subproc_run(innertest, '-k', 'app_test_raise_in_a_closure', |
| 70 |
'--runappdirect') |
| 71 |
assert len(passed) == 1 |
| 72 |
print passed |
| 73 |
assert "app_test_raise_in_a_closure" in passed[0] |