datacamp / pythonwhat

Verify Python code submissions and auto-generate meaningful feedback messages.
http://pythonwhat.readthedocs.io/
GNU Affero General Public License v3.0
67 stars 31 forks source link

test function defn with test try except issue: BLOCK BETA 9/15 #86

Closed hugobowne closed 7 years ago

hugobowne commented 7 years ago

I'm trying to use test_try_except() within test_function_definition().

I am using this as a model: https://github.com/datacamp/pythonwhat/wiki/test_try_except

No luck yet!

It seems to tell me 'name collections is not defined' :

screenshot 2016-09-12 20 27 16

SCT is here, Ch3 line618: https://www.datacamp.com/teach/edit/repositories/463/branches/SCT_edits

You get (10**100000)! points for using collections, one of my favourite python modules, if not my favourite 👍

filipsch commented 7 years ago

For some obscure reason that I can't explain myself, you have to put the import collection call inside the definition of inner_test(). It's probably a scoping issue, but I can't tell you what's really playing here.

inner_test() should look like this:

def inner_test():
    def inner_inner_test():
        test_object_after_expression("echo_word", extra_env={'word1' : 'hithere', 'echo': 2})
    import collections
    handlers = collections.OrderedDict()
    handlers['all'] = lambda: test_function('print')
    test_try_except(index = 1,
                body = inner_inner_test,
                handlers = handlers)
hugobowne commented 7 years ago

works great thx good nice!