Skip to content

Pytest fixes #9

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

Merged
merged 4 commits into from
Oct 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/DeveloperGuidelines.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ is going to bite your head off for committing something.
the work here. Paste Script contains several wrappers for external
projects (servers in particular).

* Tests are good. We use py.test_, because it is simple. I want to
* Tests are good. We use pytest_, because it is simple. I want to
use doctests too, but the infrastructure isn't really there now --
but please feel free to use those too. ``unittest`` is kind of
annoying, and py.test is both more powerful and easier to write for.
annoying, and pytest is both more powerful and easier to write for.
Tests should go in the ``tests/`` directory. ``paste.fixture``
contains some convenience functions for testing WSGI applications
and middleware. Pay particular attention to ``TestApp``.
.. _py.test: http://codespeak.net/py/current/doc/test.html

.. _pytest: https://docs.pytest.org/en/latest/

* If you move something around that someone may be using, keep their
imports working and introduce a warning, like::
Expand Down
2 changes: 1 addition & 1 deletion docs/news.txt
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ In paste.httpserver
``wdg_validate`` and ``doctest_webapp``

- a ``testserver`` module suitable to test HTTP socket
connections via ``py.test``
connections via ``pytest``

* Re-factored `paste.wsgilib <module-paste.wsgilib.html>`_ into
several other modules:
Expand Down
22 changes: 11 additions & 11 deletions paste/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@ def reset(self):
"SMTP connection not quit")
self.__class__.existing = None


class AppError(Exception):
pass


class TestApp(object):

# for py.test
disabled = True
__test__ = False # Ignore with pytest test collection.

def __init__(self, app, namespace=None, relative_to=None,
extra_environ=None, pre_request_hook=None,
Expand Down Expand Up @@ -189,8 +190,7 @@ def get(self, url, params=None, headers=None, extra_environ=None,
"""
if extra_environ is None:
extra_environ = {}
# Hide from py.test:
__tracebackhide__ = True
__tracebackhide__ = True # Hide from pytest:
if params:
if not isinstance(params, (six.binary_type, six.text_type)):
params = urlencode(params, doseq=True)
Expand Down Expand Up @@ -494,10 +494,10 @@ def writelines(self, lines):
def getvalue(self):
return self.captured.getvalue()


class TestResponse(object):

# for py.test
disabled = True
__test__ = False # Ignore with pytest test collection.

"""
Instances of this class are return by `TestApp
Expand Down Expand Up @@ -884,10 +884,10 @@ def showbrowser(self):
url = 'file:' + fn.replace(os.sep, '/')
webbrowser.open_new(url)


class TestRequest(object):

# for py.test
disabled = True
__test__ = False # Ignore with pytest test collection.

"""
Instances of this class are created by `TestApp
Expand Down Expand Up @@ -1331,8 +1331,7 @@ class TestFileEnvironment(object):
scripts will be run.
"""

# for py.test
disabled = True
__test__ = False # Ignore with pytest test collection.

def __init__(self, base_path, template_path=None,
script_path=None,
Expand Down Expand Up @@ -1722,9 +1721,10 @@ def _make_pattern(pat):
assert 0, (
"Cannot make callable pattern object out of %r" % pat)


def setup_module(module=None):
"""
This is used by py.test if it is in the module, so you can
This is used by pytest if it is in the module, so you can
import this directly.

Use like::
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ distribute = register sdist bdist_egg upload pudge publish

[bdist_wheel]
universal=1

[tool:pytest]
testpaths = tests
6 changes: 3 additions & 3 deletions tests/test_auth/test_auth_digest.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ def test_digest():
# The following code uses sockets to test the functionality,
# to enable use:
#
# $ TEST_SOCKET py.test
#
# $ TEST_SOCKET=1 pytest


if os.environ.get("TEST_SOCKET",""):
if os.environ.get("TEST_SOCKET", ""):
from six.moves.urllib.error import HTTPError
from six.moves.urllib.request import build_opener, HTTPDigestAuthHandler
from paste.debug.testserver import serve
Expand Down
26 changes: 13 additions & 13 deletions tests/test_doctests.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import six
import doctest
from paste.util.import_string import simple_import
import os

import pytest
import six

from paste.util.import_string import simple_import

filenames = [
'tests/template.txt',
]
Expand Down Expand Up @@ -30,29 +33,26 @@
if six.PY3:
options |= doctest.IGNORE_EXCEPTION_DETAIL

def test_doctests():
for filename in filenames:
filename = os.path.join(
os.path.dirname(os.path.dirname(__file__)),
filename)
yield do_doctest, filename

def do_doctest(filename):
@pytest.mark.parametrize('filename', filenames)
def test_doctests(filename):
filename = os.path.join(
os.path.dirname(os.path.dirname(__file__)),
filename)
failure, total = doctest.testfile(
filename, module_relative=False,
optionflags=options)
assert not failure, "Failure in %r" % filename

def test_doctest_mods():
for module in modules:
yield do_doctest_mod, module

def do_doctest_mod(module):
@pytest.mark.parametrize('module', modules)
def test_doctest_mods(module):
module = simple_import(module)
failure, total = doctest.testmod(
module, optionflags=options)
assert not failure, "Failure in %r" % module


if __name__ == '__main__':
import sys
import doctest
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ deps =
setenv =
coverage: PYTEST_ADDOPTS=--cov --cov-report=term-missing
commands =
py.test {posargs}
pytest {posargs}