heynemann / pyvows

Python implementation of Vows.js

Home Page:http://pyvows.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Exceptions in topic functions

ricklupton opened this issue · comments

Why are exceptions from topic functions captured and returned as the topic? This doesn't appear to be documented in either vows.js or PyVows, and at least for me it's surprising.

This is how I expect it to work:

@Vows.batch
class ErrorsInTopicFunction(Vows.Context):

    class WhenTopicRaisesAnException:
        def topic(self):
            return 42 / 0

        def tests_should_not_run(self, topic):
            raise RuntimeError("Should not reach here")
            # but instead topic is an Exception not the value you were expecting...

        class SubContext:
            def subcontexts_should_also_not_run(self, topic):
                raise RuntimeError("Should not reach here")


    class WhenTopicReturnsAnException:
        def topic(self):
            try:
                return 42 / 0
            except Exception as e:
                return e

        def it_is_passed_to_tests_as_normal(self, topic):
            expect(topic).to_be_an_error_like(ZeroDivisionError)

This seems to mean you have to check for errors in the topic function in every test function. Unless there's a reason for this behaviour, I'll submit a pull request to make the above tests pass.

Why are exceptions from topic functions captured and returned as the topic? This doesn't appear to be documented in either vows.js or PyVows, and at least for me it's surprising.

You know…that’s a good point!

It’s kind of weird to admit, but I think I was bothered by this in the past, but sort of assumed that it was the way things are just supposed to work. (I joined PyVows some time after its release.)

I totally agree with your reasoning, and I’m going to file this as a bug. If you can submit a Pull Request that fixes this, I’ll be eternally grateful. (And right now our history/changelog is semi-manually updated—which sucks—but I’ll be happy to add a credit for you in the merge. 😄 )

There are repercussions from merging this in #102…but what’s done is done. Closing. :/