New issue 472: skipif documentation has broken example using pytest.config https://bitbucket.org/hpk42/pytest/issue/472/skipif-documentation-has-broken-example
Wichert Akkerman: The [skip and xfail](https://pytest.org/latest/skipping.html) documentation has an example at the end of the page showing how to use ```pytest.config`` to make a skip conditional on the test runner configuration: ``` @pytest.mark.skipif(not pytest.config.getvalue("db"), reason="--db was not specified") def test_function(...): pass ``` I tried to use that mechanism to make a test conditional on the use of PostgreSQL with tests: ``` def pytest_generate_tests(metafunc): if 'sqlalchemy_url' in metafunc.fixturenames: metafunc.parametrize('sqlalchemy_url', [metafunc.config.option.database]) require_postgres = pytest.mark.skipif( not pytest.config.getvalue('database').startswith('postgresql'), reason='PostgreSQL database required') ``` When I try to run my tests with this I get the following error: ``` Traceback (most recent call last): File "bin/py.test", line 62, in <module> sys.exit(pytest.main()) File "/Users/wichert/Library/buildout/eggs/pytest-2.5.2-py2.7.egg/_pytest/config.py", line 19, in main config = _prepareconfig(args, plugins) File "/Users/wichert/Library/buildout/eggs/pytest-2.5.2-py2.7.egg/_pytest/config.py", line 63, in _prepareconfig pluginmanager=pluginmanager, args=args) File "/Users/wichert/Library/buildout/eggs/pytest-2.5.2-py2.7.egg/_pytest/core.py", line 377, in __call__ return self._docall(methods, kwargs) File "/Users/wichert/Library/buildout/eggs/pytest-2.5.2-py2.7.egg/_pytest/core.py", line 388, in _docall res = mc.execute() File "/Users/wichert/Library/buildout/eggs/pytest-2.5.2-py2.7.egg/_pytest/core.py", line 289, in execute res = method(**kwargs) File "/Users/wichert/Library/buildout/eggs/pytest-2.5.2-py2.7.egg/_pytest/helpconfig.py", line 27, in pytest_cmdline_parse config = __multicall__.execute() File "/Users/wichert/Library/buildout/eggs/pytest-2.5.2-py2.7.egg/_pytest/core.py", line 289, in execute res = method(**kwargs) File "/Users/wichert/Library/buildout/eggs/pytest-2.5.2-py2.7.egg/_pytest/config.py", line 618, in pytest_cmdline_parse self.parse(args) File "/Users/wichert/Library/buildout/eggs/pytest-2.5.2-py2.7.egg/_pytest/config.py", line 711, in parse self._preparse(args) File "/Users/wichert/Library/buildout/eggs/pytest-2.5.2-py2.7.egg/_pytest/config.py", line 691, in _preparse args=args, parser=self._parser) File "/Users/wichert/Library/buildout/eggs/pytest-2.5.2-py2.7.egg/_pytest/core.py", line 377, in __call__ return self._docall(methods, kwargs) File "/Users/wichert/Library/buildout/eggs/pytest-2.5.2-py2.7.egg/_pytest/core.py", line 388, in _docall res = mc.execute() File "/Users/wichert/Library/buildout/eggs/pytest-2.5.2-py2.7.egg/_pytest/core.py", line 289, in execute res = method(**kwargs) File "/Users/wichert/Library/buildout/eggs/pytest-2.5.2-py2.7.egg/_pytest/capture.py", line 83, in pytest_load_initial_conftests return __multicall__.execute() File "/Users/wichert/Library/buildout/eggs/pytest-2.5.2-py2.7.egg/_pytest/core.py", line 289, in execute res = method(**kwargs) File "/Users/wichert/Library/buildout/eggs/pytest-2.5.2-py2.7.egg/_pytest/config.py", line 674, in pytest_load_initial_conftests self._conftest.setinitial(args) File "/Users/wichert/Library/buildout/eggs/pytest-2.5.2-py2.7.egg/_pytest/config.py", line 487, in setinitial self._try_load_conftest(anchor) File "/Users/wichert/Library/buildout/eggs/pytest-2.5.2-py2.7.egg/_pytest/config.py", line 493, in _try_load_conftest self._path2confmods[None] = self.getconftestmodules(anchor) File "/Users/wichert/Library/buildout/eggs/pytest-2.5.2-py2.7.egg/_pytest/config.py", line 512, in getconftestmodules clist.append(self.importconftest(conftestpath)) File "/Users/wichert/Library/buildout/eggs/pytest-2.5.2-py2.7.egg/_pytest/config.py", line 538, in importconftest self._conftestpath2mod[conftestpath] = mod = conftestpath.pyimport() File "/Users/wichert/Library/buildout/eggs/py-1.4.20-py2.7.egg/py/_path/local.py", line 608, in pyimport __import__(pkgpath.basename) File "/Users/wichert/myapp/tests/__init__.py", line 5, in <module> not pytest.config.getvalue('database').startswith('postgres'), AttributeError: 'module' object has no attribute 'config' ``` _______________________________________________ pytest-commit mailing list pytest-commit@python.org https://mail.python.org/mailman/listinfo/pytest-commit