Skip to content

Commit

Permalink
Merge pull request #2316 from nicoddemus/add-future-imports
Browse files Browse the repository at this point in the history
Add __future__ imports to all pytest modules
  • Loading branch information
RonnyPfannschmidt authored Mar 17, 2017
2 parents 5482dfe + 4d94707 commit a122ae8
Show file tree
Hide file tree
Showing 74 changed files with 119 additions and 47 deletions.
10 changes: 5 additions & 5 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -206,12 +206,12 @@ but here is a simple overview:

#. Run all the tests

You need to have Python 2.7 and 3.5 available in your system. Now
You need to have Python 2.7 and 3.6 available in your system. Now
running tests is as simple as issuing this command::

$ tox -e linting,py27,py35
$ tox -e linting,py27,py36

This command will run tests via the "tox" tool against Python 2.7 and 3.5
This command will run tests via the "tox" tool against Python 2.7 and 3.6
and also perform "lint" coding-style checks.

#. You can now edit your local working copy.
Expand All @@ -223,9 +223,9 @@ but here is a simple overview:

$ tox -e py27 -- --pdb

Or to only run tests in a particular test module on Python 3.5::
Or to only run tests in a particular test module on Python 3.6::

$ tox -e py35 -- testing/test_config.py
$ tox -e py36 -- testing/test_config.py

#. Commit and push once your tests pass and you are happy with your change(s)::

Expand Down
2 changes: 1 addition & 1 deletion _pytest/_argcomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
which should throw a KeyError: 'COMPLINE' (which is properly set by the
global argcomplete script).
"""

from __future__ import absolute_import, division, print_function
import sys
import os
from glob import glob
Expand Down
1 change: 1 addition & 0 deletions _pytest/_code/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" python inspection/code generation API """
from __future__ import absolute_import, division, print_function
from .code import Code # noqa
from .code import ExceptionInfo # noqa
from .code import Frame # noqa
Expand Down
1 change: 1 addition & 0 deletions _pytest/_code/_py2traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# CHANGES:
# - some_str is replaced, trying to create unicode strings
#
from __future__ import absolute_import, division, print_function
import types

def format_exception_only(etype, value):
Expand Down
1 change: 1 addition & 0 deletions _pytest/_code/code.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import, division, print_function
import sys
from inspect import CO_VARARGS, CO_VARKEYWORDS
import re
Expand Down
2 changes: 1 addition & 1 deletion _pytest/_code/source.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from __future__ import generators
from __future__ import absolute_import, division, generators, print_function

from bisect import bisect_right
import sys
Expand Down
2 changes: 1 addition & 1 deletion _pytest/_pluggy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
imports symbols from vendored "pluggy" if available, otherwise
falls back to importing "pluggy" from the default namespace.
"""

from __future__ import absolute_import, division, print_function
try:
from _pytest.vendored_packages.pluggy import * # noqa
from _pytest.vendored_packages.pluggy import __version__ # noqa
Expand Down
1 change: 1 addition & 0 deletions _pytest/assertion/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
support for presenting detailed information in failing assertions.
"""
from __future__ import absolute_import, division, print_function
import py
import sys

Expand Down
2 changes: 1 addition & 1 deletion _pytest/assertion/rewrite.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Rewrite assertion AST to produce nice error messages"""

from __future__ import absolute_import, division, print_function
import ast
import _ast
import errno
Expand Down
2 changes: 1 addition & 1 deletion _pytest/assertion/truncate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Current default behaviour is to truncate assertion explanations at
~8 terminal lines, unless running in "-vv" mode or running on CI.
"""

from __future__ import absolute_import, division, print_function
import os

import py
Expand Down
1 change: 1 addition & 0 deletions _pytest/assertion/util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Utilities for assertion debugging"""
from __future__ import absolute_import, division, print_function
import pprint

import _pytest._code
Expand Down
2 changes: 1 addition & 1 deletion _pytest/cacheprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
the name cache was not chosen to ensure pluggy automatically
ignores the external pytest-cache
"""

from __future__ import absolute_import, division, print_function
import py
import pytest
import json
Expand Down
2 changes: 1 addition & 1 deletion _pytest/capture.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
per-test stdout/stderr capturing mechanism.
"""
from __future__ import with_statement
from __future__ import absolute_import, division, print_function

import contextlib
import sys
Expand Down
1 change: 1 addition & 0 deletions _pytest/compat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
python version compatibility code
"""
from __future__ import absolute_import, division, print_function
import sys
import inspect
import types
Expand Down
1 change: 1 addition & 0 deletions _pytest/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" command line options, ini-file and conftest.py processing. """
from __future__ import absolute_import, division, print_function
import argparse
import shlex
import traceback
Expand Down
2 changes: 1 addition & 1 deletion _pytest/debugging.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
""" interactive debugging with PDB, the Python Debugger. """
from __future__ import absolute_import
from __future__ import absolute_import, division, print_function
import pdb
import sys

Expand Down
2 changes: 1 addition & 1 deletion _pytest/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Keeping it in a central location makes it easy to track what is deprecated and should
be removed when the time comes.
"""

from __future__ import absolute_import, division, print_function

MAIN_STR_ARGS = 'passing a string to pytest.main() is deprecated, ' \
'pass a list of arguments instead.'
Expand Down
2 changes: 1 addition & 1 deletion _pytest/doctest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
""" discover and run doctests in modules and test files."""
from __future__ import absolute_import
from __future__ import absolute_import, division, print_function

import traceback

Expand Down
1 change: 1 addition & 0 deletions _pytest/fixtures.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import, division, print_function
import sys

from py._code.code import FormattedExcinfo
Expand Down
4 changes: 3 additions & 1 deletion _pytest/freeze_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Provides a function to report all internal modules for using freezing tools
pytest
"""
from __future__ import absolute_import, division, print_function


def pytest_namespace():
return {'freeze_includes': freeze_includes}
Expand Down Expand Up @@ -42,4 +44,4 @@ def _iter_all_modules(package, prefix=''):
for m in _iter_all_modules(os.path.join(path, name), prefix=name + '.'):
yield prefix + m
else:
yield prefix + name
yield prefix + name
2 changes: 2 additions & 0 deletions _pytest/helpconfig.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
""" version info, help messages, tracing configuration. """
from __future__ import absolute_import, division, print_function

import py
import pytest
import os, sys
Expand Down
6 changes: 4 additions & 2 deletions _pytest/junitxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
Based on initial code from Ross Lawley.
Output conforms to https://github.com/jenkinsci/xunit-plugin/blob/master/
src/main/resources/org/jenkinsci/plugins/xunit/types/model/xsd/junit-10.xsd
"""
# Output conforms to https://github.com/jenkinsci/xunit-plugin/blob/master/
# src/main/resources/org/jenkinsci/plugins/xunit/types/model/xsd/junit-10.xsd
from __future__ import absolute_import, division, print_function

import functools
import py
Expand Down
2 changes: 2 additions & 0 deletions _pytest/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
""" core implementation of testing process: init, session, runtest loop. """
from __future__ import absolute_import, division, print_function

import functools
import os
import sys
Expand Down
2 changes: 2 additions & 0 deletions _pytest/mark.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
""" generic mechanism for marking and selecting python functions. """
from __future__ import absolute_import, division, print_function

import inspect
from collections import namedtuple
from operator import attrgetter
Expand Down
1 change: 1 addition & 0 deletions _pytest/monkeypatch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" monkeypatching and mocking functionality. """
from __future__ import absolute_import, division, print_function

import os, sys
import re
Expand Down
1 change: 1 addition & 0 deletions _pytest/nose.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" run test suites written for nose. """
from __future__ import absolute_import, division, print_function

import sys

Expand Down
2 changes: 2 additions & 0 deletions _pytest/pastebin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
""" submit failure or test session information to a pastebin service. """
from __future__ import absolute_import, division, print_function

import pytest
import sys
import tempfile
Expand Down
18 changes: 9 additions & 9 deletions _pytest/pytester.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
""" (disabled by default) support for testing pytest and pytest plugins. """
from __future__ import absolute_import, division, print_function

import codecs
import gc
import os
Expand All @@ -12,8 +14,6 @@

from weakref import WeakKeyDictionary

from py.builtin import print_

from _pytest.capture import MultiCapture, SysCapture
from _pytest._code import Source
import py
Expand Down Expand Up @@ -229,15 +229,15 @@ def assert_contains(self, entries):
name, check = entries.pop(0)
for ind, call in enumerate(self.calls[i:]):
if call._name == name:
print_("NAMEMATCH", name, call)
print("NAMEMATCH", name, call)
if eval(check, backlocals, call.__dict__):
print_("CHECKERMATCH", repr(check), "->", call)
print("CHECKERMATCH", repr(check), "->", call)
else:
print_("NOCHECKERMATCH", repr(check), "-", call)
print("NOCHECKERMATCH", repr(check), "-", call)
continue
i += ind + 1
break
print_("NONAMEMATCH", name, "with", call)
print("NONAMEMATCH", name, "with", call)
else:
pytest.fail("could not find %r check %r" % (name, check))

Expand Down Expand Up @@ -924,8 +924,8 @@ def _run(self, *cmdargs):
cmdargs = [str(x) for x in cmdargs]
p1 = self.tmpdir.join("stdout")
p2 = self.tmpdir.join("stderr")
print_("running:", ' '.join(cmdargs))
print_(" in:", str(py.path.local()))
print("running:", ' '.join(cmdargs))
print(" in:", str(py.path.local()))
f1 = codecs.open(str(p1), "w", encoding="utf8")
f2 = codecs.open(str(p2), "w", encoding="utf8")
try:
Expand All @@ -951,7 +951,7 @@ def _run(self, *cmdargs):
def _dump_lines(self, lines, fp):
try:
for line in lines:
py.builtin.print_(line, file=fp)
print(line, file=fp)
except UnicodeEncodeError:
print("couldn't print to %s because of encoding" % (fp,))

Expand Down
1 change: 1 addition & 0 deletions _pytest/python.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" Python test discovery, setup and run of test functions. """
from __future__ import absolute_import, division, print_function

import fnmatch
import inspect
Expand Down
2 changes: 2 additions & 0 deletions _pytest/recwarn.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
""" recording warnings during test function execution. """
from __future__ import absolute_import, division, print_function

import inspect

import _pytest._code
Expand Down
5 changes: 3 additions & 2 deletions _pytest/resultlog.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
""" log machine-parseable test session result information in a plain
text file.
"""
from __future__ import absolute_import, division, print_function

import py
import os
Expand Down Expand Up @@ -61,9 +62,9 @@ def __init__(self, config, logfile):
self.logfile = logfile # preferably line buffered

def write_log_entry(self, testpath, lettercode, longrepr):
py.builtin.print_("%s %s" % (lettercode, testpath), file=self.logfile)
print("%s %s" % (lettercode, testpath), file=self.logfile)
for line in longrepr.splitlines():
py.builtin.print_(" %s" % line, file=self.logfile)
print(" %s" % line, file=self.logfile)

def log_outcome(self, report, lettercode, longrepr):
testpath = getattr(report, 'nodeid', None)
Expand Down
2 changes: 2 additions & 0 deletions _pytest/runner.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
""" basic collect and runtest protocol implementations """
from __future__ import absolute_import, division, print_function

import bdb
import sys
from time import time
Expand Down
2 changes: 2 additions & 0 deletions _pytest/setuponly.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import absolute_import, division, print_function

import pytest
import sys

Expand Down
2 changes: 2 additions & 0 deletions _pytest/setupplan.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import absolute_import, division, print_function

import pytest


Expand Down
2 changes: 2 additions & 0 deletions _pytest/skipping.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
""" support for skip/xfail functions and markers. """
from __future__ import absolute_import, division, print_function

import os
import sys
import traceback
Expand Down
2 changes: 2 additions & 0 deletions _pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
This is a good source for looking at the various reporting hooks.
"""
from __future__ import absolute_import, division, print_function

from _pytest.main import EXIT_OK, EXIT_TESTSFAILED, EXIT_INTERRUPTED, \
EXIT_USAGEERROR, EXIT_NOTESTSCOLLECTED
import pytest
Expand Down
2 changes: 2 additions & 0 deletions _pytest/tmpdir.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
""" support for providing temporary directories to test functions. """
from __future__ import absolute_import, division, print_function

import re

import pytest
Expand Down
2 changes: 1 addition & 1 deletion _pytest/unittest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
""" discovery and running of std-library "unittest" style tests. """
from __future__ import absolute_import
from __future__ import absolute_import, division, print_function

import sys
import traceback
Expand Down
1 change: 1 addition & 0 deletions testing/acceptance_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function
import os
import sys

Expand Down
1 change: 1 addition & 0 deletions testing/code/test_code.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import absolute_import, division, print_function
import sys

import _pytest._code
Expand Down
3 changes: 2 additions & 1 deletion testing/code/test_excinfo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function

import operator
import _pytest
Expand Down Expand Up @@ -369,7 +370,7 @@ def test_codepath_Queue_example():

def test_match_succeeds():
with pytest.raises(ZeroDivisionError) as excinfo:
0 / 0
0 // 0
excinfo.match(r'.*zero.*')

def test_match_raises_error(testdir):
Expand Down
Loading

0 comments on commit a122ae8

Please sign in to comment.