diff --git a/_pytest/pytester.py b/_pytest/pytester.py index f9da97b18..619bba988 100644 --- a/_pytest/pytester.py +++ b/_pytest/pytester.py @@ -236,13 +236,14 @@ class TmpTestdir: def _makefile(self, ext, args, kwargs): items = list(kwargs.items()) if args: - source = "\n".join(map(str, args)) + "\n" + source = py.builtin._totext("\n").join( + map(py.builtin._totext, args)) + py.builtin._totext("\n") basename = self.request.function.__name__ items.insert(0, (basename, source)) ret = None for name, value in items: p = self.tmpdir.join(name).new(ext=ext) - source = str(py.code.Source(value)).lstrip() + source = py.builtin._totext(py.code.Source(value)).lstrip() p.write(source.encode("utf-8"), "wb") if ret is None: ret = p diff --git a/testing/test_pytester.py b/testing/test_pytester.py index 8b246d7d1..0501ee200 100644 --- a/testing/test_pytester.py +++ b/testing/test_pytester.py @@ -1,3 +1,4 @@ +import py import pytest import os, sys from _pytest.pytester import LineMatcher, LineComp, HookRecorder @@ -113,3 +114,12 @@ def test_functional(testdir, linecomp): assert res == [42] """) reprec.assertoutcome(passed=1) + + +def test_makepyfile_unicode(testdir): + global unichr + try: + unichr(65) + except NameError: + unichr = chr + testdir.makepyfile(unichr(0xfffd))