Clean up __future__ and coding: in tests

This commit is contained in:
Anthony Sottile 2019-06-02 15:40:34 -07:00 committed by Bruno Oliveira
parent a91fe1fedd
commit 4df529e5b9
15 changed files with 27 additions and 63 deletions

View File

@ -335,8 +335,6 @@ string value of ``Hello World!`` if we do not supply a value or ``Hello
.. code-block:: python .. code-block:: python
# -*- coding: utf-8 -*-
import pytest import pytest

View File

@ -507,14 +507,13 @@ class TestGeneralUsage:
def test_parametrized_with_null_bytes(self, testdir): def test_parametrized_with_null_bytes(self, testdir):
"""Test parametrization with values that contain null bytes and unicode characters (#2644, #2957)""" """Test parametrization with values that contain null bytes and unicode characters (#2644, #2957)"""
p = testdir.makepyfile( p = testdir.makepyfile(
""" """\
# encoding: UTF-8
import pytest import pytest
@pytest.mark.parametrize("data", [b"\\x00", "\\x00", u'ação']) @pytest.mark.parametrize("data", [b"\\x00", "\\x00", u'ação'])
def test_foo(data): def test_foo(data):
assert data assert data
""" """
) )
res = testdir.runpytest(p) res = testdir.runpytest(p)
res.assert_outcomes(passed=3) res.assert_outcomes(passed=3)

View File

@ -840,16 +840,14 @@ def test_log_file_unicode(testdir):
) )
) )
testdir.makepyfile( testdir.makepyfile(
""" """\
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import logging import logging
def test_log_file(): def test_log_file():
logging.getLogger('catchlog').info("Normal message") logging.getLogger('catchlog').info("Normal message")
logging.getLogger('catchlog').info("") logging.getLogger('catchlog').info("")
logging.getLogger('catchlog').info("Another normal message") logging.getLogger('catchlog').info("Another normal message")
""" """
) )
result = testdir.runpytest() result = testdir.runpytest()

View File

@ -116,12 +116,7 @@ class TestModule:
"""Check test modules collected which raise ImportError with unicode messages """Check test modules collected which raise ImportError with unicode messages
are handled properly (#2336). are handled properly (#2336).
""" """
testdir.makepyfile( testdir.makepyfile("raise ImportError(u'Something bad happened ☺')")
"""
# -*- coding: utf-8 -*-
raise ImportError(u'Something bad happened ☺')
"""
)
result = testdir.runpytest() result = testdir.runpytest()
result.stdout.fnmatch_lines( result.stdout.fnmatch_lines(
[ [
@ -1256,13 +1251,7 @@ def test_class_injection_does_not_break_collection(testdir):
def test_syntax_error_with_non_ascii_chars(testdir): def test_syntax_error_with_non_ascii_chars(testdir):
"""Fix decoding issue while formatting SyntaxErrors during collection (#578) """Fix decoding issue while formatting SyntaxErrors during collection (#578)
""" """
testdir.makepyfile( testdir.makepyfile("")
"""
# -*- coding: utf-8 -*-
"""
)
result = testdir.runpytest() result = testdir.runpytest()
result.stdout.fnmatch_lines(["*ERROR collecting*", "*SyntaxError*", "*1 error in*"]) result.stdout.fnmatch_lines(["*ERROR collecting*", "*SyntaxError*", "*1 error in*"])

View File

@ -3338,7 +3338,6 @@ class TestContextManagerFixtureFuncs:
def test_simple(self, testdir, flavor): def test_simple(self, testdir, flavor):
testdir.makepyfile( testdir.makepyfile(
""" """
from __future__ import print_function
from test_context import fixture from test_context import fixture
@fixture @fixture
def arg1(): def arg1():
@ -3367,7 +3366,6 @@ class TestContextManagerFixtureFuncs:
def test_scoped(self, testdir, flavor): def test_scoped(self, testdir, flavor):
testdir.makepyfile( testdir.makepyfile(
""" """
from __future__ import print_function
from test_context import fixture from test_context import fixture
@fixture(scope="module") @fixture(scope="module")
def arg1(): def arg1():
@ -3601,7 +3599,6 @@ class TestParameterizedSubRequest:
def test_pytest_fixture_setup_and_post_finalizer_hook(testdir): def test_pytest_fixture_setup_and_post_finalizer_hook(testdir):
testdir.makeconftest( testdir.makeconftest(
""" """
from __future__ import print_function
def pytest_fixture_setup(fixturedef, request): def pytest_fixture_setup(fixturedef, request):
print('ROOT setup hook called for {0} from {1}'.format(fixturedef.argname, request.node.name)) print('ROOT setup hook called for {0} from {1}'.format(fixturedef.argname, request.node.name))
def pytest_fixture_post_finalizer(fixturedef, request): def pytest_fixture_post_finalizer(fixturedef, request):
@ -3611,14 +3608,12 @@ def test_pytest_fixture_setup_and_post_finalizer_hook(testdir):
testdir.makepyfile( testdir.makepyfile(
**{ **{
"tests/conftest.py": """ "tests/conftest.py": """
from __future__ import print_function
def pytest_fixture_setup(fixturedef, request): def pytest_fixture_setup(fixturedef, request):
print('TESTS setup hook called for {0} from {1}'.format(fixturedef.argname, request.node.name)) print('TESTS setup hook called for {0} from {1}'.format(fixturedef.argname, request.node.name))
def pytest_fixture_post_finalizer(fixturedef, request): def pytest_fixture_post_finalizer(fixturedef, request):
print('TESTS finalizer hook called for {0} from {1}'.format(fixturedef.argname, request.node.name)) print('TESTS finalizer hook called for {0} from {1}'.format(fixturedef.argname, request.node.name))
""", """,
"tests/test_hooks.py": """ "tests/test_hooks.py": """
from __future__ import print_function
import pytest import pytest
@pytest.fixture() @pytest.fixture()

View File

@ -1217,11 +1217,10 @@ def test_assert_indirect_tuple_no_warning(testdir):
def test_assert_with_unicode(monkeypatch, testdir): def test_assert_with_unicode(monkeypatch, testdir):
testdir.makepyfile( testdir.makepyfile(
""" """\
# -*- coding: utf-8 -*-
def test_unicode(): def test_unicode():
assert u'유니코드' == u'Unicode' assert u'유니코드' == u'Unicode'
""" """
) )
result = testdir.runpytest() result = testdir.runpytest()
result.stdout.fnmatch_lines(["*AssertionError*"]) result.stdout.fnmatch_lines(["*AssertionError*"])

View File

@ -95,14 +95,13 @@ def test_capturing_unicode(testdir, method):
pytest.xfail("does not work on pypy < 2.2") pytest.xfail("does not work on pypy < 2.2")
obj = "'b\u00f6y'" obj = "'b\u00f6y'"
testdir.makepyfile( testdir.makepyfile(
""" """\
# -*- coding: utf-8 -*-
# taken from issue 227 from nosetests # taken from issue 227 from nosetests
def test_unicode(): def test_unicode():
import sys import sys
print(sys.stdout) print(sys.stdout)
print(%s) print(%s)
""" """
% obj % obj
) )
result = testdir.runpytest("--capture=%s" % method) result = testdir.runpytest("--capture=%s" % method)
@ -624,7 +623,6 @@ class TestCaptureFixture:
""" """
testdir.makepyfile( testdir.makepyfile(
"""\ """\
from __future__ import print_function
import sys import sys
import pytest import pytest
@ -1363,7 +1361,6 @@ def test_dontreadfrominput_has_encoding(testdir):
def test_crash_on_closing_tmpfile_py27(testdir): def test_crash_on_closing_tmpfile_py27(testdir):
p = testdir.makepyfile( p = testdir.makepyfile(
""" """
from __future__ import print_function
import threading import threading
import sys import sys

View File

@ -574,14 +574,13 @@ class TestDoctests:
"""Fix internal error with docstrings containing non-ascii characters. """Fix internal error with docstrings containing non-ascii characters.
""" """
testdir.makepyfile( testdir.makepyfile(
''' '''\
# -*- coding: utf-8 -*-
def foo(): def foo():
""" """
>>> name = 'с' # not letter 'c' but instead Cyrillic 's'. >>> name = 'с' # not letter 'c' but instead Cyrillic 's'.
'anything' 'anything'
""" """
''' '''
) )
result = testdir.runpytest("--doctest-modules") result = testdir.runpytest("--doctest-modules")
result.stdout.fnmatch_lines(["Got nothing", "* 1 failed in*"]) result.stdout.fnmatch_lines(["Got nothing", "* 1 failed in*"])
@ -652,9 +651,6 @@ class TestDoctests:
""" """
p = testdir.makepyfile( p = testdir.makepyfile(
test_unicode_doctest_module=""" test_unicode_doctest_module="""
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
def fix_bad_unicode(text): def fix_bad_unicode(text):
''' '''
>>> print(fix_bad_unicode('único')) >>> print(fix_bad_unicode('único'))

View File

@ -567,12 +567,12 @@ class TestPython:
def test_unicode(self, testdir): def test_unicode(self, testdir):
value = "hx\xc4\x85\xc4\x87\n" value = "hx\xc4\x85\xc4\x87\n"
testdir.makepyfile( testdir.makepyfile(
""" """\
# coding: latin1 # coding: latin1
def test_hello(): def test_hello():
print(%r) print(%r)
assert 0 assert 0
""" """
% value % value
) )
result, dom = runandparse(testdir) result, dom = runandparse(testdir)

View File

@ -960,7 +960,6 @@ def test_markers_from_parametrize(testdir):
"""#3605""" """#3605"""
testdir.makepyfile( testdir.makepyfile(
""" """
from __future__ import print_function
import pytest import pytest
first_custom_mark = pytest.mark.custom_marker first_custom_mark = pytest.mark.custom_marker

View File

@ -366,13 +366,12 @@ def test_nottest_class_decorator(testdir):
def test_skip_test_with_unicode(testdir): def test_skip_test_with_unicode(testdir):
testdir.makepyfile( testdir.makepyfile(
""" """\
# -*- coding: utf-8 -*-
import unittest import unittest
class TestClass(): class TestClass():
def test_io(self): def test_io(self):
raise unittest.SkipTest(u'😊') raise unittest.SkipTest(u'😊')
""" """
) )
result = testdir.runpytest() result = testdir.runpytest()
result.stdout.fnmatch_lines(["* 1 skipped *"]) result.stdout.fnmatch_lines(["* 1 skipped *"])

View File

@ -60,11 +60,10 @@ class TestPasteCapture:
correctly. See #1219. correctly. See #1219.
""" """
testdir.makepyfile( testdir.makepyfile(
test_unicode=""" test_unicode="""\
# -*- coding: utf-8 -*-
def test(): def test():
assert '' == 1 assert '' == 1
""" """
) )
result = testdir.runpytest("--pastebin=all") result = testdir.runpytest("--pastebin=all")
expected_msg = "*assert '' == 1*" expected_msg = "*assert '' == 1*"

View File

@ -149,12 +149,11 @@ def test_importplugin_error_message(testdir, pytestpm):
""" """
testdir.syspathinsert(testdir.tmpdir) testdir.syspathinsert(testdir.tmpdir)
testdir.makepyfile( testdir.makepyfile(
qwe=""" qwe="""\
# -*- coding: utf-8 -*-
def test_traceback(): def test_traceback():
raise ImportError(u'Not possible to import: ☺') raise ImportError('Not possible to import: ☺')
test_traceback() test_traceback()
""" """
) )
with pytest.raises(ImportError) as excinfo: with pytest.raises(ImportError) as excinfo:
pytestpm.import_plugin("qwe") pytestpm.import_plugin("qwe")

View File

@ -639,13 +639,12 @@ def test_pytest_fail_notrace_non_ascii(testdir, str_prefix):
This tests with native and unicode strings containing non-ascii chars. This tests with native and unicode strings containing non-ascii chars.
""" """
testdir.makepyfile( testdir.makepyfile(
""" """\
# -*- coding: utf-8 -*-
import pytest import pytest
def test_hello(): def test_hello():
pytest.fail(%s'oh oh: ☺', pytrace=False) pytest.fail(%s'oh oh: ☺', pytrace=False)
""" """
% str_prefix % str_prefix
) )
result = testdir.runpytest() result = testdir.runpytest()
@ -784,8 +783,7 @@ def test_pytest_cmdline_main(testdir):
def test_unicode_in_longrepr(testdir): def test_unicode_in_longrepr(testdir):
testdir.makeconftest( testdir.makeconftest(
""" """\
# -*- coding: utf-8 -*-
import pytest import pytest
@pytest.hookimpl(hookwrapper=True) @pytest.hookimpl(hookwrapper=True)
def pytest_runtest_makereport(): def pytest_runtest_makereport():
@ -793,7 +791,7 @@ def test_unicode_in_longrepr(testdir):
rep = outcome.get_result() rep = outcome.get_result()
if rep.when == "call": if rep.when == "call":
rep.longrepr = u'ä' rep.longrepr = u'ä'
""" """
) )
testdir.makepyfile( testdir.makepyfile(
""" """

View File

@ -123,8 +123,7 @@ def test_ignore(testdir, pyfile_with_warnings, method):
@pytest.mark.filterwarnings("always") @pytest.mark.filterwarnings("always")
def test_unicode(testdir, pyfile_with_warnings): def test_unicode(testdir, pyfile_with_warnings):
testdir.makepyfile( testdir.makepyfile(
""" """\
# -*- coding: utf-8 -*-
import warnings import warnings
import pytest import pytest
@ -136,7 +135,7 @@ def test_unicode(testdir, pyfile_with_warnings):
def test_func(fix): def test_func(fix):
pass pass
""" """
) )
result = testdir.runpytest() result = testdir.runpytest()
result.stdout.fnmatch_lines( result.stdout.fnmatch_lines(