You probably want a template with just a couple of lines like
answer = """{{ STUDENT_ANSWER | e('py') }}"""
compile(answer, '<string>', 'exec')
But you'll still need to set up a test case with empty expected output and a dummy 'testcode' (perhaps just a comment to say the code is being checked).
A nicer approach would be to use a combinator template grader, which doesn't require any test cases and doesn't need to generate a result table. But that's way harder.
You might also want to consider more-advanced checking than just "does it compile?". See the python3_pylint question type, introduced in the documentation here.