diff --git a/doc/en/writing_plugins.rst b/doc/en/writing_plugins.rst index 04dc68b64..469ee57ca 100644 --- a/doc/en/writing_plugins.rst +++ b/doc/en/writing_plugins.rst @@ -335,8 +335,6 @@ string value of ``Hello World!`` if we do not supply a value or ``Hello .. code-block:: python - # -*- coding: utf-8 -*- - import pytest diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 9d0d7f863..9d903f802 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -507,14 +507,13 @@ class TestGeneralUsage: def test_parametrized_with_null_bytes(self, testdir): """Test parametrization with values that contain null bytes and unicode characters (#2644, #2957)""" p = testdir.makepyfile( - """ - # encoding: UTF-8 + """\ import pytest @pytest.mark.parametrize("data", [b"\\x00", "\\x00", u'ação']) def test_foo(data): assert data - """ + """ ) res = testdir.runpytest(p) res.assert_outcomes(passed=3) diff --git a/testing/logging/test_reporting.py b/testing/logging/test_reporting.py index f845f5c39..fc775b951 100644 --- a/testing/logging/test_reporting.py +++ b/testing/logging/test_reporting.py @@ -840,16 +840,14 @@ def test_log_file_unicode(testdir): ) ) testdir.makepyfile( - """ - # -*- coding: utf-8 -*- - from __future__ import unicode_literals + """\ import logging def test_log_file(): logging.getLogger('catchlog').info("Normal message") logging.getLogger('catchlog').info("├") logging.getLogger('catchlog').info("Another normal message") - """ + """ ) result = testdir.runpytest() diff --git a/testing/python/collect.py b/testing/python/collect.py index 544e71f25..981e30fc3 100644 --- a/testing/python/collect.py +++ b/testing/python/collect.py @@ -116,12 +116,7 @@ class TestModule: """Check test modules collected which raise ImportError with unicode messages are handled properly (#2336). """ - testdir.makepyfile( - """ - # -*- coding: utf-8 -*- - raise ImportError(u'Something bad happened ☺') - """ - ) + testdir.makepyfile("raise ImportError(u'Something bad happened ☺')") result = testdir.runpytest() 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): """Fix decoding issue while formatting SyntaxErrors during collection (#578) """ - testdir.makepyfile( - """ - # -*- coding: utf-8 -*- - - ☃ - """ - ) + testdir.makepyfile("☃") result = testdir.runpytest() result.stdout.fnmatch_lines(["*ERROR collecting*", "*SyntaxError*", "*1 error in*"]) diff --git a/testing/python/fixtures.py b/testing/python/fixtures.py index 3b14dc835..2dc3b4308 100644 --- a/testing/python/fixtures.py +++ b/testing/python/fixtures.py @@ -3338,7 +3338,6 @@ class TestContextManagerFixtureFuncs: def test_simple(self, testdir, flavor): testdir.makepyfile( """ - from __future__ import print_function from test_context import fixture @fixture def arg1(): @@ -3367,7 +3366,6 @@ class TestContextManagerFixtureFuncs: def test_scoped(self, testdir, flavor): testdir.makepyfile( """ - from __future__ import print_function from test_context import fixture @fixture(scope="module") def arg1(): @@ -3601,7 +3599,6 @@ class TestParameterizedSubRequest: def test_pytest_fixture_setup_and_post_finalizer_hook(testdir): testdir.makeconftest( """ - from __future__ import print_function def pytest_fixture_setup(fixturedef, request): print('ROOT setup hook called for {0} from {1}'.format(fixturedef.argname, request.node.name)) def pytest_fixture_post_finalizer(fixturedef, request): @@ -3611,14 +3608,12 @@ def test_pytest_fixture_setup_and_post_finalizer_hook(testdir): testdir.makepyfile( **{ "tests/conftest.py": """ - from __future__ import print_function def pytest_fixture_setup(fixturedef, request): print('TESTS setup hook called for {0} from {1}'.format(fixturedef.argname, request.node.name)) def pytest_fixture_post_finalizer(fixturedef, request): print('TESTS finalizer hook called for {0} from {1}'.format(fixturedef.argname, request.node.name)) """, "tests/test_hooks.py": """ - from __future__ import print_function import pytest @pytest.fixture() diff --git a/testing/test_assertion.py b/testing/test_assertion.py index 6102f9578..e651c09ce 100644 --- a/testing/test_assertion.py +++ b/testing/test_assertion.py @@ -1217,11 +1217,10 @@ def test_assert_indirect_tuple_no_warning(testdir): def test_assert_with_unicode(monkeypatch, testdir): testdir.makepyfile( - """ - # -*- coding: utf-8 -*- + """\ def test_unicode(): assert u'유니코드' == u'Unicode' - """ + """ ) result = testdir.runpytest() result.stdout.fnmatch_lines(["*AssertionError*"]) diff --git a/testing/test_capture.py b/testing/test_capture.py index 1657f05d9..0825745ad 100644 --- a/testing/test_capture.py +++ b/testing/test_capture.py @@ -95,14 +95,13 @@ def test_capturing_unicode(testdir, method): pytest.xfail("does not work on pypy < 2.2") obj = "'b\u00f6y'" testdir.makepyfile( - """ - # -*- coding: utf-8 -*- + """\ # taken from issue 227 from nosetests def test_unicode(): import sys print(sys.stdout) print(%s) - """ + """ % obj ) result = testdir.runpytest("--capture=%s" % method) @@ -624,7 +623,6 @@ class TestCaptureFixture: """ testdir.makepyfile( """\ - from __future__ import print_function import sys import pytest @@ -1363,7 +1361,6 @@ def test_dontreadfrominput_has_encoding(testdir): def test_crash_on_closing_tmpfile_py27(testdir): p = testdir.makepyfile( """ - from __future__ import print_function import threading import sys diff --git a/testing/test_doctest.py b/testing/test_doctest.py index 54b23e15d..65c8cf366 100644 --- a/testing/test_doctest.py +++ b/testing/test_doctest.py @@ -574,14 +574,13 @@ class TestDoctests: """Fix internal error with docstrings containing non-ascii characters. """ testdir.makepyfile( - ''' - # -*- coding: utf-8 -*- + '''\ def foo(): """ >>> name = 'с' # not letter 'c' but instead Cyrillic 's'. 'anything' """ - ''' + ''' ) result = testdir.runpytest("--doctest-modules") result.stdout.fnmatch_lines(["Got nothing", "* 1 failed in*"]) @@ -652,9 +651,6 @@ class TestDoctests: """ p = testdir.makepyfile( test_unicode_doctest_module=""" - # -*- coding: utf-8 -*- - from __future__ import unicode_literals - def fix_bad_unicode(text): ''' >>> print(fix_bad_unicode('único')) diff --git a/testing/test_junitxml.py b/testing/test_junitxml.py index aa7287fb5..69b9c09c3 100644 --- a/testing/test_junitxml.py +++ b/testing/test_junitxml.py @@ -567,12 +567,12 @@ class TestPython: def test_unicode(self, testdir): value = "hx\xc4\x85\xc4\x87\n" testdir.makepyfile( - """ + """\ # coding: latin1 def test_hello(): print(%r) assert 0 - """ + """ % value ) result, dom = runandparse(testdir) diff --git a/testing/test_mark.py b/testing/test_mark.py index c66b85568..8d97f8b4e 100644 --- a/testing/test_mark.py +++ b/testing/test_mark.py @@ -960,7 +960,6 @@ def test_markers_from_parametrize(testdir): """#3605""" testdir.makepyfile( """ - from __future__ import print_function import pytest first_custom_mark = pytest.mark.custom_marker diff --git a/testing/test_nose.py b/testing/test_nose.py index b726c9682..8a3ce6454 100644 --- a/testing/test_nose.py +++ b/testing/test_nose.py @@ -366,13 +366,12 @@ def test_nottest_class_decorator(testdir): def test_skip_test_with_unicode(testdir): testdir.makepyfile( - """ - # -*- coding: utf-8 -*- + """\ import unittest class TestClass(): def test_io(self): raise unittest.SkipTest(u'😊') - """ + """ ) result = testdir.runpytest() result.stdout.fnmatch_lines(["* 1 skipped *"]) diff --git a/testing/test_pastebin.py b/testing/test_pastebin.py index eb2fd8fae..48dea14bd 100644 --- a/testing/test_pastebin.py +++ b/testing/test_pastebin.py @@ -60,11 +60,10 @@ class TestPasteCapture: correctly. See #1219. """ testdir.makepyfile( - test_unicode=""" - # -*- coding: utf-8 -*- + test_unicode="""\ def test(): assert '☺' == 1 - """ + """ ) result = testdir.runpytest("--pastebin=all") expected_msg = "*assert '☺' == 1*" diff --git a/testing/test_pluginmanager.py b/testing/test_pluginmanager.py index 4e476fc01..8afb37fa1 100644 --- a/testing/test_pluginmanager.py +++ b/testing/test_pluginmanager.py @@ -149,12 +149,11 @@ def test_importplugin_error_message(testdir, pytestpm): """ testdir.syspathinsert(testdir.tmpdir) testdir.makepyfile( - qwe=""" - # -*- coding: utf-8 -*- + qwe="""\ def test_traceback(): - raise ImportError(u'Not possible to import: ☺') + raise ImportError('Not possible to import: ☺') test_traceback() - """ + """ ) with pytest.raises(ImportError) as excinfo: pytestpm.import_plugin("qwe") diff --git a/testing/test_runner.py b/testing/test_runner.py index 61828294b..77fdcecc3 100644 --- a/testing/test_runner.py +++ b/testing/test_runner.py @@ -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. """ testdir.makepyfile( - """ - # -*- coding: utf-8 -*- + """\ import pytest def test_hello(): pytest.fail(%s'oh oh: ☺', pytrace=False) - """ + """ % str_prefix ) result = testdir.runpytest() @@ -784,8 +783,7 @@ def test_pytest_cmdline_main(testdir): def test_unicode_in_longrepr(testdir): testdir.makeconftest( - """ - # -*- coding: utf-8 -*- + """\ import pytest @pytest.hookimpl(hookwrapper=True) def pytest_runtest_makereport(): @@ -793,7 +791,7 @@ def test_unicode_in_longrepr(testdir): rep = outcome.get_result() if rep.when == "call": rep.longrepr = u'ä' - """ + """ ) testdir.makepyfile( """ diff --git a/testing/test_warnings.py b/testing/test_warnings.py index 0046709f3..1d6128273 100644 --- a/testing/test_warnings.py +++ b/testing/test_warnings.py @@ -123,8 +123,7 @@ def test_ignore(testdir, pyfile_with_warnings, method): @pytest.mark.filterwarnings("always") def test_unicode(testdir, pyfile_with_warnings): testdir.makepyfile( - """ - # -*- coding: utf-8 -*- + """\ import warnings import pytest @@ -136,7 +135,7 @@ def test_unicode(testdir, pyfile_with_warnings): def test_func(fix): pass - """ + """ ) result = testdir.runpytest() result.stdout.fnmatch_lines(