How to debug a template

Re: How to debug a template

by Jim Newton -
Number of replies: 5

I wondered whether the "Check" button might do something different than "Save changes" button.

save button

So I attached a file to the answer on the question editing page, and clicked on "Validate on save".

test answer

Unfortunately I still don't see any debugging information anywhere.  In fact the message in red indicates that the test failed, and that for more detailed information I should save the question with "Validate on save" unchecked and test manually.

It is not at all clear to me how to rest manually, since I haven't yet figured out what is being run. That's basically what I'm trying to debug.

In reply to Jim Newton

Re: How to debug a template

by Jenny Harlow -

"Debugging a template" means debugging the code that processes and grades the student answer.  You would use it when you were trying to work out what was going wrong in that processing/marking. 

When you click that 'Template debugging' option in the template question authoring form, then save the question, then preview+put in answer+click check you will see the code that is actually going to be run 'under the hood' to mark the student's response. 

In particular, you see that code after the TWIG stuff has happened (ie, instead of seeing the TWIG placeholders for the student answer, test code, etc, you see what has been put in for those placeholders).

I suggest that the best way to see what should be happening, in general, is to take one of the built-in question types, make a question based on that type (or use an example one from the provided examples in the docs), click the customise box to customise that individual question and then click for template debugging and untick validate on save.  Then save the question, preview it, put in some kind of answer, and click check. 

As I say, that will show you what you could expect to see (based on that particular question type) and that might help you in working out why you are not seeing something equivalent for your particular question.

Jenny

 

In reply to Jenny Harlow

Re: How to debug a template

by Jim Newton -

Thanks Jenny, that's helpful information. I don't know what you mean by prievew+put etc.

In reply to Jenny Harlow

Re: How to debug a template

by Jim Newton -

What do you mean exactly by: 

you will see the code that is actually going to be run 'under the hood' to mark the student's response. 

Where should I see this?  Is it in a popup window?  Should it appear in the red region which says: Your code must pass all tests... ?   Or does it appear in a link somewhere which I need to click on?


red region

In reply to Jenny Harlow

Re: How to debug a template

by Jim Newton -

HI Jenny, do I understand correctly that debugging a template only means to see the twig output which is expected to see a valid python program.   Moreover, debugging is not intended to show me the stdout and stderr of actually running that python program in the specially prepared directory with the specially prepared environment?

What I'd like to figure out is what does the python script (output by twig) do when run in the directory containing the student's submitted file.  The suggestion that I "save the message with 'Validate on save' unchecked and test manually", doesn't really help me figure out what I need to know, as far as I can understand.    Am I missing something crucial?

red message

In reply to Jenny Harlow

Re: How to debug a template

by Jim Newton -
Hi Jenny, What controls whether debugging is enabled?  Is it 100% my pressing the debug template button, or is there something which my system administrator has to enable?  By administrator I mean the person who installed and maintains the moodle and who installed CodeRunner.