From e860ff7299fa3618db73cffbadeb95b135754a08 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Tue, 26 Jun 2018 22:59:40 +0200 Subject: [PATCH] port some acceptance tests over to copy_example --- src/_pytest/pytester.py | 5 ++++- testing/acceptance_test.py | 21 ++----------------- .../conftest_usageerror/conftest.py | 4 ++++ .../conftest.py | 14 +++++++++++++ .../test_hello.py | 2 ++ testing/examples/test_issue519.py | 3 +++ 6 files changed, 29 insertions(+), 20 deletions(-) create mode 100644 testing/example_scripts/conftest_usageerror/conftest.py create mode 100644 testing/example_scripts/issue88_initial_file_multinodes/conftest.py create mode 100644 testing/example_scripts/issue88_initial_file_multinodes/test_hello.py create mode 100644 testing/examples/test_issue519.py diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py index 245b35d14..8cbcf6a09 100644 --- a/src/_pytest/pytester.py +++ b/src/_pytest/pytester.py @@ -635,7 +635,10 @@ class Testdir(object): def copy_example(self, name): example_dir = self.request.config.getini("pytester_example_dir") 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 diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 88c1f8740..6f12cc335 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -14,13 +14,7 @@ from _pytest.main import EXIT_NOTESTSCOLLECTED, EXIT_USAGEERROR class TestGeneralUsage(object): def test_config_error(self, testdir): - testdir.makeconftest( - """ - def pytest_configure(config): - import pytest - raise pytest.UsageError("hello") - """ - ) + testdir.copy_example("conftest_usageerror/conftest.py") result = testdir.runpytest(testdir.tmpdir) assert result.ret != 0 result.stderr.fnmatch_lines(["*ERROR: hello"]) @@ -170,18 +164,7 @@ class TestGeneralUsage(object): result.stdout.fnmatch_lines(["*1 skip*"]) def test_issue88_initial_file_multinodes(self, testdir): - testdir.makeconftest( - """ - 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 - """ - ) + testdir.copy_example("issue88_initial_file_multinodes") p = testdir.makepyfile("def test_hello(): pass") result = testdir.runpytest(p, "--collect-only") result.stdout.fnmatch_lines(["*MyFile*test_issue88*", "*Module*test_issue88*"]) diff --git a/testing/example_scripts/conftest_usageerror/conftest.py b/testing/example_scripts/conftest_usageerror/conftest.py new file mode 100644 index 000000000..7d0d39d3a --- /dev/null +++ b/testing/example_scripts/conftest_usageerror/conftest.py @@ -0,0 +1,4 @@ +def pytest_configure(config): + import pytest + + raise pytest.UsageError("hello") diff --git a/testing/example_scripts/issue88_initial_file_multinodes/conftest.py b/testing/example_scripts/issue88_initial_file_multinodes/conftest.py new file mode 100644 index 000000000..aa5d87831 --- /dev/null +++ b/testing/example_scripts/issue88_initial_file_multinodes/conftest.py @@ -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 diff --git a/testing/example_scripts/issue88_initial_file_multinodes/test_hello.py b/testing/example_scripts/issue88_initial_file_multinodes/test_hello.py new file mode 100644 index 000000000..56444d147 --- /dev/null +++ b/testing/example_scripts/issue88_initial_file_multinodes/test_hello.py @@ -0,0 +1,2 @@ +def test_hello(): + pass diff --git a/testing/examples/test_issue519.py b/testing/examples/test_issue519.py new file mode 100644 index 000000000..e83f18fdc --- /dev/null +++ b/testing/examples/test_issue519.py @@ -0,0 +1,3 @@ +def test_510(testdir): + testdir.copy_example("issue_519.py") + testdir.runpytest("issue_519.py")