konira icon indicating copy to clipboard operation
konira copied to clipboard

Improve case class filter

Open superduper opened this issue 11 years ago • 1 comments

There's a problem with case class harvester: https://github.com/alfredodeza/konira/blob/master/konira/runner.py#L234-L236

When you have a global var that has no __name__ attribute in your spec:

from functools import partial
foo = partial(dict, yay=1)

describe "feature": 
    it "does something cool":
        print "yay!"

It will choke on bootstrap:

$ find . -name "*.pyc" -exec rm -f {} \;
$ konira -x -t -s tests/case_foo.py

Errors:
-------

1 ==> AttributeError: 'functools.partial' object has no attribute '__name__'
File: /Users/dada/.virtualenvs/dada/lib/python2.7/site-packages/konira/runner.py:236:
Traceback (most recent call last):
  File "/Users/dada/.virtualenvs/dada/lib/python2.7/site-packages/konira/runner.py", line 236, in _collect_classes
    return [i for i in global_modules[0].values() if callable(i) and i.__name__.startswith('Case_')]
AttributeError: 'functools.partial' object has no attribute '__name__'

This patch will fix it :)

superduper avatar Oct 09 '13 17:10 superduper

The patch looks good! Would you be able to add some test cases to make sure your fix works and we don't break it in the future?

alfredodeza avatar Oct 09 '13 17:10 alfredodeza