Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def template_test(schema_version, schema, data, is_valid):
"""
Test function to be used (imported) in final test file to run the tests
which are generated by `pytest_generate_tests` hook.
"""
# For debug purposes. When test fails, it will print stdout.
resolver = RefResolver.from_schema(schema, handlers={'http': remotes_handler})
debug_generator = _get_code_generator_class(schema_version)(schema, resolver=resolver)
print(debug_generator.global_state_code)
print(debug_generator.func_code)
# JSON schema test suits do not contain schema version.
# Our library needs to know that or it would use always the latest implementation.
if isinstance(schema, dict):
schema.setdefault('$schema', schema_version)
validate = compile(schema, handlers={'http': remotes_handler})
try:
result = validate(data)
print('Validate result:', result)
except JsonSchemaException:
if is_valid:
raise
else: