pytest / testing / test_helpconfig.py

import py, pytest,os
from _pytest.helpconfig import collectattr

def test_version(testdir, pytestconfig):
    result = testdir.runpytest("--version")
    assert result.ret == 0
    #p = py.path.local(py.__file__).dirpath()
    result.stderr.fnmatch_lines([
        '*py.test*%s*imported from*' % (pytest.__version__, )
    ])
    if pytestconfig.pluginmanager._plugin_distinfo:
        result.stderr.fnmatch_lines([
            "*setuptools registered plugins:",
            "*at*",
        ])

def test_help(testdir):
    result = testdir.runpytest("--help")
    assert result.ret == 0
    result.stdout.fnmatch_lines("""
        *-v*verbose*
        *setup.cfg*
        *minversion*
        *to see*markers*py.test --markers*
        *to see*fixtures*py.test --fixtures*
    """)

def test_collectattr():
    class A:
        def pytest_hello(self):
            pass
    class B(A):
        def pytest_world(self):
            pass
    methods = py.builtin.sorted(collectattr(B))
    assert list(methods) == ['pytest_hello', 'pytest_world']
    methods = py.builtin.sorted(collectattr(B()))
    assert list(methods) == ['pytest_hello', 'pytest_world']

def test_hookvalidation_unknown(testdir):
    testdir.makeconftest("""
        def pytest_hello(xyz):
            pass
    """)
    result = testdir.runpytest()
    assert result.ret != 0
    result.stderr.fnmatch_lines([
        '*unknown hook*pytest_hello*'
    ])

def test_hookvalidation_optional(testdir):
    testdir.makeconftest("""
        import pytest
        @pytest.mark.optionalhook
        def pytest_hello(xyz):
            pass
    """)
    result = testdir.runpytest()
    assert result.ret == 0

def test_traceconfig(testdir):
    result = testdir.runpytest("--traceconfig")
    result.stdout.fnmatch_lines([
        "*using*pytest*py*",
        "*active plugins*",
    ])

def test_debug(testdir, monkeypatch):
    result = testdir.runpytest("--debug")
    assert result.ret == 0
    p = testdir.tmpdir.join("pytestdebug.log")
    assert "pytest_sessionstart" in p.read()

def test_PYTEST_DEBUG(testdir, monkeypatch):
    monkeypatch.setenv("PYTEST_DEBUG", "1")
    result = testdir.runpytest()
    assert result.ret == 0
    result.stderr.fnmatch_lines([
        "*pytest_plugin_registered*",
        "*manager*PluginManager*"
    ])
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.