port some acceptance tests over to copy_example

This commit is contained in:
Ronny Pfannschmidt 2018-06-26 22:59:40 +02:00
parent 0672bc633f
commit e860ff7299
6 changed files with 29 additions and 20 deletions

View File

@ -635,7 +635,10 @@ class Testdir(object):
def copy_example(self, name): def copy_example(self, name):
example_dir = self.request.config.getini("pytester_example_dir") example_dir = self.request.config.getini("pytester_example_dir")
example_path = self.request.config.rootdir.join(example_dir, name) example_path = self.request.config.rootdir.join(example_dir, name)
example_path.copy(self.tmpdir.join(example_path.basename)) if example_path.isdir() and not example_path.join("__init__.py").isfile():
example_path.copy(self.tmpdir)
else:
example_path.copy(self.tmpdir.join(example_path.basename))
Session = Session Session = Session

View File

@ -14,13 +14,7 @@ from _pytest.main import EXIT_NOTESTSCOLLECTED, EXIT_USAGEERROR
class TestGeneralUsage(object): class TestGeneralUsage(object):
def test_config_error(self, testdir): def test_config_error(self, testdir):
testdir.makeconftest( testdir.copy_example("conftest_usageerror/conftest.py")
"""
def pytest_configure(config):
import pytest
raise pytest.UsageError("hello")
"""
)
result = testdir.runpytest(testdir.tmpdir) result = testdir.runpytest(testdir.tmpdir)
assert result.ret != 0 assert result.ret != 0
result.stderr.fnmatch_lines(["*ERROR: hello"]) result.stderr.fnmatch_lines(["*ERROR: hello"])
@ -170,18 +164,7 @@ class TestGeneralUsage(object):
result.stdout.fnmatch_lines(["*1 skip*"]) result.stdout.fnmatch_lines(["*1 skip*"])
def test_issue88_initial_file_multinodes(self, testdir): def test_issue88_initial_file_multinodes(self, testdir):
testdir.makeconftest( testdir.copy_example("issue88_initial_file_multinodes")
"""
import pytest
class MyFile(pytest.File):
def collect(self):
return [MyItem("hello", parent=self)]
def pytest_collect_file(path, parent):
return MyFile(path, parent)
class MyItem(pytest.Item):
pass
"""
)
p = testdir.makepyfile("def test_hello(): pass") p = testdir.makepyfile("def test_hello(): pass")
result = testdir.runpytest(p, "--collect-only") result = testdir.runpytest(p, "--collect-only")
result.stdout.fnmatch_lines(["*MyFile*test_issue88*", "*Module*test_issue88*"]) result.stdout.fnmatch_lines(["*MyFile*test_issue88*", "*Module*test_issue88*"])

View File

@ -0,0 +1,4 @@
def pytest_configure(config):
import pytest
raise pytest.UsageError("hello")

View File

@ -0,0 +1,14 @@
import pytest
class MyFile(pytest.File):
def collect(self):
return [MyItem("hello", parent=self)]
def pytest_collect_file(path, parent):
return MyFile(path, parent)
class MyItem(pytest.Item):
pass

View File

@ -0,0 +1,2 @@
def test_hello():
pass

View File

@ -0,0 +1,3 @@
def test_510(testdir):
testdir.copy_example("issue_519.py")
testdir.runpytest("issue_519.py")