Skip to content

Commit 35eba8f

Browse files
committed
Use temporary dir in tests for compiled code
1 parent e8aa21e commit 35eba8f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

tests/test_compile_to_code.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def test_compile_to_code_custom_format():
9999
assert exc.value.message == "data must be my-format"
100100

101101

102-
def test_compile_to_code_custom_format_with_refs():
102+
def test_compile_to_code_custom_format_with_refs(tmp_path, monkeypatch):
103103
schema = {
104104
'type': 'object',
105105
'properties': {
@@ -115,9 +115,12 @@ def test_compile_to_code_custom_format_with_refs():
115115
}
116116
formats = {'my-format': str.isidentifier}
117117
code = compile_to_code(schema, formats=formats)
118-
with open('temp/schema_4.py', 'w') as f:
119-
f.write(code)
120-
from temp.schema_4 import validate
118+
119+
(tmp_path / "schema_4.py").write_text(code)
120+
with monkeypatch.context() as m:
121+
m.syspath_prepend(tmp_path)
122+
from schema_4 import validate
123+
121124
assert validate({"a": ["identifier"]}, formats) is not None
122125
with pytest.raises(JsonSchemaValueException) as exc:
123126
validate({"a": ["identifier", "not-valid"]}, formats)

0 commit comments

Comments
 (0)