Skip to content

Commit

Permalink
Merge pull request #1 from artyom-smirnov/python_test_debug
Browse files Browse the repository at this point in the history
Allow to debug python tests
  • Loading branch information
pcisar committed Feb 14, 2019
2 parents ccf8a42 + 0896088 commit fe7fec2
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion fbtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,19 @@ def get_log():
try:
sys.stdout = StringIO()
sys.stderr = StringIO()
exec substitute_macros(self.test_script) in global_ns, local_ns
# put Python code into temporary file to allow easy debugging
test_src = substitute_macros(self.test_script)
temp_src_file = tempfile.NamedTemporaryFile(dir=context.environment['temp_directory'], delete=False,
suffix='.py')
if isinstance(test_src, types.UnicodeType):
test_src = test_src.encode('utf-8')
temp_src_file.write(test_src)
temp_src_file.close()
try:
test_code_block = compile(test_src, temp_src_file.name, 'exec')
exec test_code_block in global_ns, local_ns
finally:
os.unlink(temp_src_file.name)
except KeyboardInterrupt:
raise
except:
Expand Down

0 comments on commit fe7fec2

Please sign in to comment.