diff --git a/scripts/check_cassettes.py b/scripts/check_cassettes.py index a2ddd63a1d..94987bcd71 100644 --- a/scripts/check_cassettes.py +++ b/scripts/check_cassettes.py @@ -56,7 +56,7 @@ def _has_module_vcr_marker(tree: ast.Module) -> bool: def _collect_vcr_tests_from_file(path: Path) -> set[str]: """Parse a Python test file and return cassette names for VCR-marked tests.""" try: - tree = ast.parse(path.read_text()) + tree = ast.parse(path.read_text(encoding='utf-8')) except SyntaxError: return set() diff --git a/tests/test_check_cassettes.py b/tests/test_check_cassettes.py new file mode 100644 index 0000000000..ef4f2b3145 --- /dev/null +++ b/tests/test_check_cassettes.py @@ -0,0 +1,21 @@ +from pathlib import Path + +from scripts.check_cassettes import _collect_vcr_tests_from_file + + +def test_collect_vcr_tests_reads_utf8_source(tmp_path: Path) -> None: + test_file = tmp_path / 'test_unicode_source.py' + test_file.write_text( + """\ +import pytest + + +@pytest.mark.vcr +def test_unicode_source_comment(): + message = 'Olá, 世界' + assert message +""", + encoding='utf-8', + ) + + assert _collect_vcr_tests_from_file(test_file) == {'test_unicode_source_comment'}