Skip to content

Commit 6dfe498

Browse files
github-actions[bot]bluetech
andauthoredJul 8, 2023
[7.4.x] doc: fix EncodingWarnings in examples (#11182)
Co-authored-by: Ran Benita <[email protected]>
1 parent a566b78 commit 6dfe498

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed
 

‎doc/en/example/nonpython/conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def collect(self):
1212
# We need a yaml parser, e.g. PyYAML.
1313
import yaml
1414

15-
raw = yaml.safe_load(self.path.open())
15+
raw = yaml.safe_load(self.path.open(encoding="utf-8"))
1616
for name, spec in sorted(raw.items()):
1717
yield YamlItem.from_parent(self, name=name, spec=spec)
1818

‎doc/en/example/simple.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ case we just write some information out to a ``failures`` file:
817817
# we only look at actual failing test calls, not setup/teardown
818818
if rep.when == "call" and rep.failed:
819819
mode = "a" if os.path.exists("failures") else "w"
820-
with open("failures", mode) as f:
820+
with open("failures", mode, encoding="utf-8") as f:
821821
# let's also access a fixture for the fun of it
822822
if "tmp_path" in item.fixturenames:
823823
extra = " ({})".format(item.funcargs["tmp_path"])

‎doc/en/how-to/fixtures.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1698,7 +1698,7 @@ and declare its use in a test module via a ``usefixtures`` marker:
16981698
class TestDirectoryInit:
16991699
def test_cwd_starts_empty(self):
17001700
assert os.listdir(os.getcwd()) == []
1701-
with open("myfile", "w") as f:
1701+
with open("myfile", "w", encoding="utf-8") as f:
17021702
f.write("hello")
17031703
17041704
def test_cwd_again_starts_empty(self):

‎doc/en/how-to/tmp_path.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ created in the `base temporary directory`_.
2424
d = tmp_path / "sub"
2525
d.mkdir()
2626
p = d / "hello.txt"
27-
p.write_text(CONTENT)
28-
assert p.read_text() == CONTENT
27+
p.write_text(CONTENT, encoding="utf-8")
28+
assert p.read_text(encoding="utf-8") == CONTENT
2929
assert len(list(tmp_path.iterdir())) == 1
3030
assert 0
3131

‎doc/en/how-to/unittest.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,10 @@ creation of a per-test temporary directory:
207207
@pytest.fixture(autouse=True)
208208
def initdir(self, tmp_path, monkeypatch):
209209
monkeypatch.chdir(tmp_path) # change to pytest-provided temporary directory
210-
tmp_path.joinpath("samplefile.ini").write_text("# testdata")
210+
tmp_path.joinpath("samplefile.ini").write_text("# testdata", encoding="utf-8")
211211
212212
def test_method(self):
213-
with open("samplefile.ini") as f:
213+
with open("samplefile.ini", encoding="utf-8") as f:
214214
s = f.read()
215215
assert "testdata" in s
216216

0 commit comments

Comments
 (0)
Please sign in to comment.