@@ -287,7 +287,8 @@ def spam(request):
287
287
def spam():
288
288
return 'spam'
289
289
"""
290
- )
290
+ ),
291
+ encoding = "utf-8" ,
291
292
)
292
293
testfile = subdir .joinpath ("test_spam.py" )
293
294
testfile .write_text (
@@ -296,7 +297,8 @@ def spam():
296
297
def test_spam(spam):
297
298
assert spam == "spam"
298
299
"""
299
- )
300
+ ),
301
+ encoding = "utf-8" ,
300
302
)
301
303
result = pytester .runpytest ()
302
304
result .stdout .fnmatch_lines (["*1 passed*" ])
@@ -359,7 +361,8 @@ def spam():
359
361
def spam(request):
360
362
return request.param
361
363
"""
362
- )
364
+ ),
365
+ encoding = "utf-8" ,
363
366
)
364
367
testfile = subdir .joinpath ("test_spam.py" )
365
368
testfile .write_text (
@@ -371,7 +374,8 @@ def test_spam(spam):
371
374
assert spam == params['spam']
372
375
params['spam'] += 1
373
376
"""
374
- )
377
+ ),
378
+ encoding = "utf-8" ,
375
379
)
376
380
result = pytester .runpytest ()
377
381
result .stdout .fnmatch_lines (["*3 passed*" ])
@@ -403,7 +407,8 @@ def spam():
403
407
def spam(request):
404
408
return request.param
405
409
"""
406
- )
410
+ ),
411
+ encoding = "utf-8" ,
407
412
)
408
413
testfile = subdir .joinpath ("test_spam.py" )
409
414
testfile .write_text (
@@ -415,7 +420,8 @@ def test_spam(spam):
415
420
assert spam == params['spam']
416
421
params['spam'] += 1
417
422
"""
418
- )
423
+ ),
424
+ encoding = "utf-8" ,
419
425
)
420
426
result = pytester .runpytest ()
421
427
result .stdout .fnmatch_lines (["*3 passed*" ])
@@ -1037,10 +1043,11 @@ def test_fixtures_sub_subdir_normalize_sep(self, pytester: Pytester) -> None:
1037
1043
def arg1():
1038
1044
pass
1039
1045
"""
1040
- )
1046
+ ),
1047
+ encoding = "utf-8" ,
1041
1048
)
1042
1049
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" )
1044
1051
result = pytester .runpytest (p , "--fixtures" )
1045
1052
assert result .ret == 0
1046
1053
result .stdout .fnmatch_lines (
@@ -1617,15 +1624,17 @@ def test_parsefactories_relative_node_ids(
1617
1624
def one():
1618
1625
return 1
1619
1626
"""
1620
- )
1627
+ ),
1628
+ encoding = "utf-8" ,
1621
1629
)
1622
1630
package .joinpath ("test_x.py" ).write_text (
1623
1631
textwrap .dedent (
1624
1632
"""\
1625
1633
def test_x(one):
1626
1634
assert one == 1
1627
1635
"""
1628
- )
1636
+ ),
1637
+ encoding = "utf-8" ,
1629
1638
)
1630
1639
sub = package .joinpath ("sub" )
1631
1640
sub .mkdir ()
@@ -1638,15 +1647,17 @@ def test_x(one):
1638
1647
def one():
1639
1648
return 2
1640
1649
"""
1641
- )
1650
+ ),
1651
+ encoding = "utf-8" ,
1642
1652
)
1643
1653
sub .joinpath ("test_y.py" ).write_text (
1644
1654
textwrap .dedent (
1645
1655
"""\
1646
1656
def test_x(one):
1647
1657
assert one == 2
1648
1658
"""
1649
- )
1659
+ ),
1660
+ encoding = "utf-8" ,
1650
1661
)
1651
1662
reprec = pytester .inline_run ()
1652
1663
reprec .assertoutcome (passed = 2 )
@@ -1671,7 +1682,8 @@ def setup_module():
1671
1682
def teardown_module():
1672
1683
values[:] = []
1673
1684
"""
1674
- )
1685
+ ),
1686
+ encoding = "utf-8" ,
1675
1687
)
1676
1688
package .joinpath ("test_x.py" ).write_text (
1677
1689
textwrap .dedent (
@@ -1680,7 +1692,8 @@ def teardown_module():
1680
1692
def test_x():
1681
1693
assert values == ["package"]
1682
1694
"""
1683
- )
1695
+ ),
1696
+ encoding = "utf-8" ,
1684
1697
)
1685
1698
package = pytester .mkdir ("package2" )
1686
1699
package .joinpath ("__init__.py" ).write_text (
@@ -1692,7 +1705,8 @@ def setup_module():
1692
1705
def teardown_module():
1693
1706
values[:] = []
1694
1707
"""
1695
- )
1708
+ ),
1709
+ encoding = "utf-8" ,
1696
1710
)
1697
1711
package .joinpath ("test_x.py" ).write_text (
1698
1712
textwrap .dedent (
@@ -1701,7 +1715,8 @@ def teardown_module():
1701
1715
def test_x():
1702
1716
assert values == ["package2"]
1703
1717
"""
1704
- )
1718
+ ),
1719
+ encoding = "utf-8" ,
1705
1720
)
1706
1721
reprec = pytester .inline_run ()
1707
1722
reprec .assertoutcome (passed = 2 )
@@ -1714,7 +1729,7 @@ def test_package_fixture_complex(self, pytester: Pytester) -> None:
1714
1729
)
1715
1730
pytester .syspathinsert (pytester .path .name )
1716
1731
package = pytester .mkdir ("package" )
1717
- package .joinpath ("__init__.py" ).write_text ("" )
1732
+ package .joinpath ("__init__.py" ).write_text ("" , encoding = "utf-8" )
1718
1733
package .joinpath ("conftest.py" ).write_text (
1719
1734
textwrap .dedent (
1720
1735
"""\
@@ -1731,7 +1746,8 @@ def two():
1731
1746
yield values
1732
1747
values.pop()
1733
1748
"""
1734
- )
1749
+ ),
1750
+ encoding = "utf-8" ,
1735
1751
)
1736
1752
package .joinpath ("test_x.py" ).write_text (
1737
1753
textwrap .dedent (
@@ -1742,7 +1758,8 @@ def test_package_autouse():
1742
1758
def test_package(one):
1743
1759
assert values == ["package-auto", "package"]
1744
1760
"""
1745
- )
1761
+ ),
1762
+ encoding = "utf-8" ,
1746
1763
)
1747
1764
reprec = pytester .inline_run ()
1748
1765
reprec .assertoutcome (passed = 2 )
@@ -1892,8 +1909,12 @@ def hello():
1892
1909
"""
1893
1910
)
1894
1911
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
+ )
1897
1918
result = pytester .runpytest ()
1898
1919
result .stdout .fnmatch_lines (
1899
1920
"""
@@ -1939,7 +1960,8 @@ def app():
1939
1960
import sys
1940
1961
sys._myapp = "hello"
1941
1962
"""
1942
- )
1963
+ ),
1964
+ encoding = "utf-8" ,
1943
1965
)
1944
1966
sub = pkgdir .joinpath ("tests" )
1945
1967
sub .mkdir ()
@@ -1952,7 +1974,8 @@ def app():
1952
1974
def test_app():
1953
1975
assert sys._myapp == "hello"
1954
1976
"""
1955
- )
1977
+ ),
1978
+ encoding = "utf-8" ,
1956
1979
)
1957
1980
reprec = pytester .inline_run ("-s" )
1958
1981
reprec .assertoutcome (passed = 1 )
@@ -2882,7 +2905,7 @@ def test_fixture_finalizer(self, pytester: Pytester) -> None:
2882
2905
def browser(request):
2883
2906
2884
2907
def finalize():
2885
- sys.stdout.write_text('Finalized')
2908
+ sys.stdout.write_text('Finalized', encoding='utf-8' )
2886
2909
request.addfinalizer(finalize)
2887
2910
return {}
2888
2911
"""
@@ -2900,7 +2923,8 @@ def browser(browser):
2900
2923
def test_browser(browser):
2901
2924
assert browser['visited'] is True
2902
2925
"""
2903
- )
2926
+ ),
2927
+ encoding = "utf-8" ,
2904
2928
)
2905
2929
reprec = pytester .runpytest ("-s" )
2906
2930
for test in ["test_browser" ]:
@@ -3855,7 +3879,8 @@ def test_non_relative_path(self, pytester: Pytester) -> None:
3855
3879
def fix_with_param(request):
3856
3880
return request.param
3857
3881
"""
3858
- )
3882
+ ),
3883
+ encoding = "utf-8" ,
3859
3884
)
3860
3885
3861
3886
testfile = tests_dir .joinpath ("test_foos.py" )
@@ -3867,7 +3892,8 @@ def fix_with_param(request):
3867
3892
def test_foo(request):
3868
3893
request.getfixturevalue('fix_with_param')
3869
3894
"""
3870
- )
3895
+ ),
3896
+ encoding = "utf-8" ,
3871
3897
)
3872
3898
3873
3899
os .chdir (tests_dir )
@@ -4196,7 +4222,7 @@ def test_multiple_packages(self, pytester: Pytester) -> None:
4196
4222
└── test_2.py
4197
4223
"""
4198
4224
root = pytester .mkdir ("root" )
4199
- root .joinpath ("__init__.py" ).write_text ("values = []" )
4225
+ root .joinpath ("__init__.py" ).write_text ("values = []" , encoding = "utf-8" )
4200
4226
sub1 = root .joinpath ("sub1" )
4201
4227
sub1 .mkdir ()
4202
4228
sub1 .joinpath ("__init__.py" ).touch ()
@@ -4211,7 +4237,8 @@ def fix():
4211
4237
yield values
4212
4238
assert values.pop() == "pre-sub1"
4213
4239
"""
4214
- )
4240
+ ),
4241
+ encoding = "utf-8" ,
4215
4242
)
4216
4243
sub1 .joinpath ("test_1.py" ).write_text (
4217
4244
textwrap .dedent (
@@ -4220,7 +4247,8 @@ def fix():
4220
4247
def test_1(fix):
4221
4248
assert values == ["pre-sub1"]
4222
4249
"""
4223
- )
4250
+ ),
4251
+ encoding = "utf-8" ,
4224
4252
)
4225
4253
sub2 = root .joinpath ("sub2" )
4226
4254
sub2 .mkdir ()
@@ -4236,7 +4264,8 @@ def fix():
4236
4264
yield values
4237
4265
assert values.pop() == "pre-sub2"
4238
4266
"""
4239
- )
4267
+ ),
4268
+ encoding = "utf-8" ,
4240
4269
)
4241
4270
sub2 .joinpath ("test_2.py" ).write_text (
4242
4271
textwrap .dedent (
@@ -4245,7 +4274,8 @@ def fix():
4245
4274
def test_2(fix):
4246
4275
assert values == ["pre-sub2"]
4247
4276
"""
4248
- )
4277
+ ),
4278
+ encoding = "utf-8" ,
4249
4279
)
4250
4280
reprec = pytester .inline_run ()
4251
4281
reprec .assertoutcome (passed = 2 )
0 commit comments