@@ -287,7 +287,8 @@ def spam(request):
287287 def spam():
288288 return 'spam'
289289 """
290- )
290+ ),
291+ encoding = "utf-8" ,
291292 )
292293 testfile = subdir .joinpath ("test_spam.py" )
293294 testfile .write_text (
@@ -296,7 +297,8 @@ def spam():
296297 def test_spam(spam):
297298 assert spam == "spam"
298299 """
299- )
300+ ),
301+ encoding = "utf-8" ,
300302 )
301303 result = pytester .runpytest ()
302304 result .stdout .fnmatch_lines (["*1 passed*" ])
@@ -359,7 +361,8 @@ def spam():
359361 def spam(request):
360362 return request.param
361363 """
362- )
364+ ),
365+ encoding = "utf-8" ,
363366 )
364367 testfile = subdir .joinpath ("test_spam.py" )
365368 testfile .write_text (
@@ -371,7 +374,8 @@ def test_spam(spam):
371374 assert spam == params['spam']
372375 params['spam'] += 1
373376 """
374- )
377+ ),
378+ encoding = "utf-8" ,
375379 )
376380 result = pytester .runpytest ()
377381 result .stdout .fnmatch_lines (["*3 passed*" ])
@@ -403,7 +407,8 @@ def spam():
403407 def spam(request):
404408 return request.param
405409 """
406- )
410+ ),
411+ encoding = "utf-8" ,
407412 )
408413 testfile = subdir .joinpath ("test_spam.py" )
409414 testfile .write_text (
@@ -415,7 +420,8 @@ def test_spam(spam):
415420 assert spam == params['spam']
416421 params['spam'] += 1
417422 """
418- )
423+ ),
424+ encoding = "utf-8" ,
419425 )
420426 result = pytester .runpytest ()
421427 result .stdout .fnmatch_lines (["*3 passed*" ])
@@ -1037,10 +1043,11 @@ def test_fixtures_sub_subdir_normalize_sep(self, pytester: Pytester) -> None:
10371043 def arg1():
10381044 pass
10391045 """
1040- )
1046+ ),
1047+ encoding = "utf-8" ,
10411048 )
10421049 p = b .joinpath ("test_module.py" )
1043- p .write_text ("def test_func(arg1): pass" )
1050+ p .write_text ("def test_func(arg1): pass" , encoding = "utf-8" )
10441051 result = pytester .runpytest (p , "--fixtures" )
10451052 assert result .ret == 0
10461053 result .stdout .fnmatch_lines (
@@ -1617,15 +1624,17 @@ def test_parsefactories_relative_node_ids(
16171624 def one():
16181625 return 1
16191626 """
1620- )
1627+ ),
1628+ encoding = "utf-8" ,
16211629 )
16221630 package .joinpath ("test_x.py" ).write_text (
16231631 textwrap .dedent (
16241632 """\
16251633 def test_x(one):
16261634 assert one == 1
16271635 """
1628- )
1636+ ),
1637+ encoding = "utf-8" ,
16291638 )
16301639 sub = package .joinpath ("sub" )
16311640 sub .mkdir ()
@@ -1638,15 +1647,17 @@ def test_x(one):
16381647 def one():
16391648 return 2
16401649 """
1641- )
1650+ ),
1651+ encoding = "utf-8" ,
16421652 )
16431653 sub .joinpath ("test_y.py" ).write_text (
16441654 textwrap .dedent (
16451655 """\
16461656 def test_x(one):
16471657 assert one == 2
16481658 """
1649- )
1659+ ),
1660+ encoding = "utf-8" ,
16501661 )
16511662 reprec = pytester .inline_run ()
16521663 reprec .assertoutcome (passed = 2 )
@@ -1671,7 +1682,8 @@ def setup_module():
16711682 def teardown_module():
16721683 values[:] = []
16731684 """
1674- )
1685+ ),
1686+ encoding = "utf-8" ,
16751687 )
16761688 package .joinpath ("test_x.py" ).write_text (
16771689 textwrap .dedent (
@@ -1680,7 +1692,8 @@ def teardown_module():
16801692 def test_x():
16811693 assert values == ["package"]
16821694 """
1683- )
1695+ ),
1696+ encoding = "utf-8" ,
16841697 )
16851698 package = pytester .mkdir ("package2" )
16861699 package .joinpath ("__init__.py" ).write_text (
@@ -1692,7 +1705,8 @@ def setup_module():
16921705 def teardown_module():
16931706 values[:] = []
16941707 """
1695- )
1708+ ),
1709+ encoding = "utf-8" ,
16961710 )
16971711 package .joinpath ("test_x.py" ).write_text (
16981712 textwrap .dedent (
@@ -1701,7 +1715,8 @@ def teardown_module():
17011715 def test_x():
17021716 assert values == ["package2"]
17031717 """
1704- )
1718+ ),
1719+ encoding = "utf-8" ,
17051720 )
17061721 reprec = pytester .inline_run ()
17071722 reprec .assertoutcome (passed = 2 )
@@ -1714,7 +1729,7 @@ def test_package_fixture_complex(self, pytester: Pytester) -> None:
17141729 )
17151730 pytester .syspathinsert (pytester .path .name )
17161731 package = pytester .mkdir ("package" )
1717- package .joinpath ("__init__.py" ).write_text ("" )
1732+ package .joinpath ("__init__.py" ).write_text ("" , encoding = "utf-8" )
17181733 package .joinpath ("conftest.py" ).write_text (
17191734 textwrap .dedent (
17201735 """\
@@ -1731,7 +1746,8 @@ def two():
17311746 yield values
17321747 values.pop()
17331748 """
1734- )
1749+ ),
1750+ encoding = "utf-8" ,
17351751 )
17361752 package .joinpath ("test_x.py" ).write_text (
17371753 textwrap .dedent (
@@ -1742,7 +1758,8 @@ def test_package_autouse():
17421758 def test_package(one):
17431759 assert values == ["package-auto", "package"]
17441760 """
1745- )
1761+ ),
1762+ encoding = "utf-8" ,
17461763 )
17471764 reprec = pytester .inline_run ()
17481765 reprec .assertoutcome (passed = 2 )
@@ -1892,8 +1909,12 @@ def hello():
18921909 """
18931910 )
18941911 conftest .rename (a .joinpath (conftest .name ))
1895- a .joinpath ("test_something.py" ).write_text ("def test_func(): pass" )
1896- b .joinpath ("test_otherthing.py" ).write_text ("def test_func(): pass" )
1912+ a .joinpath ("test_something.py" ).write_text (
1913+ "def test_func(): pass" , encoding = "utf-8"
1914+ )
1915+ b .joinpath ("test_otherthing.py" ).write_text (
1916+ "def test_func(): pass" , encoding = "utf-8"
1917+ )
18971918 result = pytester .runpytest ()
18981919 result .stdout .fnmatch_lines (
18991920 """
@@ -1939,7 +1960,8 @@ def app():
19391960 import sys
19401961 sys._myapp = "hello"
19411962 """
1942- )
1963+ ),
1964+ encoding = "utf-8" ,
19431965 )
19441966 sub = pkgdir .joinpath ("tests" )
19451967 sub .mkdir ()
@@ -1952,7 +1974,8 @@ def app():
19521974 def test_app():
19531975 assert sys._myapp == "hello"
19541976 """
1955- )
1977+ ),
1978+ encoding = "utf-8" ,
19561979 )
19571980 reprec = pytester .inline_run ("-s" )
19581981 reprec .assertoutcome (passed = 1 )
@@ -2882,7 +2905,7 @@ def test_fixture_finalizer(self, pytester: Pytester) -> None:
28822905 def browser(request):
28832906
28842907 def finalize():
2885- sys.stdout.write_text('Finalized')
2908+ sys.stdout.write_text('Finalized', encoding='utf-8' )
28862909 request.addfinalizer(finalize)
28872910 return {}
28882911 """
@@ -2900,7 +2923,8 @@ def browser(browser):
29002923 def test_browser(browser):
29012924 assert browser['visited'] is True
29022925 """
2903- )
2926+ ),
2927+ encoding = "utf-8" ,
29042928 )
29052929 reprec = pytester .runpytest ("-s" )
29062930 for test in ["test_browser" ]:
@@ -3855,7 +3879,8 @@ def test_non_relative_path(self, pytester: Pytester) -> None:
38553879 def fix_with_param(request):
38563880 return request.param
38573881 """
3858- )
3882+ ),
3883+ encoding = "utf-8" ,
38593884 )
38603885
38613886 testfile = tests_dir .joinpath ("test_foos.py" )
@@ -3867,7 +3892,8 @@ def fix_with_param(request):
38673892 def test_foo(request):
38683893 request.getfixturevalue('fix_with_param')
38693894 """
3870- )
3895+ ),
3896+ encoding = "utf-8" ,
38713897 )
38723898
38733899 os .chdir (tests_dir )
@@ -4196,7 +4222,7 @@ def test_multiple_packages(self, pytester: Pytester) -> None:
41964222 └── test_2.py
41974223 """
41984224 root = pytester .mkdir ("root" )
4199- root .joinpath ("__init__.py" ).write_text ("values = []" )
4225+ root .joinpath ("__init__.py" ).write_text ("values = []" , encoding = "utf-8" )
42004226 sub1 = root .joinpath ("sub1" )
42014227 sub1 .mkdir ()
42024228 sub1 .joinpath ("__init__.py" ).touch ()
@@ -4211,7 +4237,8 @@ def fix():
42114237 yield values
42124238 assert values.pop() == "pre-sub1"
42134239 """
4214- )
4240+ ),
4241+ encoding = "utf-8" ,
42154242 )
42164243 sub1 .joinpath ("test_1.py" ).write_text (
42174244 textwrap .dedent (
@@ -4220,7 +4247,8 @@ def fix():
42204247 def test_1(fix):
42214248 assert values == ["pre-sub1"]
42224249 """
4223- )
4250+ ),
4251+ encoding = "utf-8" ,
42244252 )
42254253 sub2 = root .joinpath ("sub2" )
42264254 sub2 .mkdir ()
@@ -4236,7 +4264,8 @@ def fix():
42364264 yield values
42374265 assert values.pop() == "pre-sub2"
42384266 """
4239- )
4267+ ),
4268+ encoding = "utf-8" ,
42404269 )
42414270 sub2 .joinpath ("test_2.py" ).write_text (
42424271 textwrap .dedent (
@@ -4245,7 +4274,8 @@ def fix():
42454274 def test_2(fix):
42464275 assert values == ["pre-sub2"]
42474276 """
4248- )
4277+ ),
4278+ encoding = "utf-8" ,
42494279 )
42504280 reprec = pytester .inline_run ()
42514281 reprec .assertoutcome (passed = 2 )
0 commit comments