Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pytester runexamples #3623

Merged
Merged
Diff settings

Always

Just for now

Copy path View file
@@ -53,6 +53,10 @@ def pytest_addoption(parser):
),
)

parser.addini(
"pytester_example_dir", help="directory to take the pytester example files from"
)


def pytest_configure(config):
if config.getvalue("lsof"):
@@ -628,6 +632,14 @@ def mkpydir(self, name):
p.ensure("__init__.py")
return p

def copy_example(self, name):
example_dir = self.request.config.getini("pytester_example_dir")

This comment has been minimized.

Copy link
@nicoddemus

nicoddemus Jun 27, 2018

Member

Probably makes sense to raise an error if pytester_example_dir is None.

This comment has been minimized.

Copy link
@nicoddemus

nicoddemus Jun 27, 2018

Member

Should we mark this as experimental?

This comment has been minimized.

Copy link
@RonnyPfannschmidt

RonnyPfannschmidt Jun 27, 2018

Author Member

yes we should - what mechanism do we want to use for that?

example_path = self.request.config.rootdir.join(example_dir, name)
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

def getnode(self, config, arg):
Copy path View file
@@ -14,13 +14,7 @@

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 @@ def pytest_collect_directory():
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*"])
@@ -0,0 +1,4 @@
def pytest_configure(config):
import pytest

raise pytest.UsageError("hello")
@@ -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
@@ -0,0 +1,2 @@
def test_hello():
pass
@@ -0,0 +1,3 @@
def test_510(testdir):
testdir.copy_example("issue_519.py")
testdir.runpytest("issue_519.py")
Copy path View file
@@ -204,7 +204,7 @@ filterwarnings =
ignore:.*type argument to addoption.*:DeprecationWarning
# produced by python >=3.5 on execnet (pytest-xdist)
ignore:.*inspect.getargspec.*deprecated, use inspect.signature.*:DeprecationWarning

pytester_example_dir = testing/example_scripts
[flake8]
max-line-length = 120
ignore = E203,W503
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.