Xion / pyqcy

QuickCheck-like testing framework for Python
http://xion.io/pyqcy
Other
41 stars 0 forks source link

nosetests isn't picking up tests #15

Closed beloglazov closed 12 years ago

beloglazov commented 12 years ago

Hi Karol,

Thanks for fixing the previous issue. There's another one, nosetests isn't picking up tests:

from pyqcy import *

class Arithmetic(TestCase):

    @qc
    def addition_on_ints(x=int, y=int):
        assert isinstance(x + y, int)

    @qc
    def subtraction_on_ints(x=int, y=int):
        assert isinstance(x - y, int)
$ nosetests test_pyqcy.py

----------------------------------------------------------------------
Ran 0 tests in 0.000s

OK

Cheers, Anton

Xion commented 12 years ago

I couldn't reproduce that:

$ mkdir test && cd test
$ vim test_pyqcy.py
...
$ mkvirtualenv pyqcytest
$ pip install pyqcy nose
$ nosetests

<errors edited out>

----------------------------------------------------------------------
Ran 2 tests in 0.008s

FAILED (errors=1)

$ nosetests test_pyqcy.py

<errors edited out>

----------------------------------------------------------------------
Ran 2 tests in 0.008s

FAILED (errors=1)

Maybe you have some configuration options for Nose that prevent it from picking up the test?

beloglazov commented 12 years ago

You are right, sorry for that. I had copied the __init__.py from pyqcy's tests directory, it had TestCase.__test__ = False in it. Once I've removed that, it started seeing the tests.

Just two more quick questions:

1) Do you know why nosetests reports that it ran 2 tests when there is just one, as in the following example?

from pyqcy import *

class Arithmetic(TestCase):

    @qc
    def addition_on_ints(x=int, y=int):
        assert True
$ nosetests test_pyqcy.py

..
----------------------------------------------------------------------
Ran 2 tests in 0.012s

OK

There's no other files in that directory.

2) And another question (probably a stupid one, sorry for that): why do the tests from my first post (addition_on_ints and subtraction_on_ints) fail?

Thanks!

Xion commented 12 years ago

I'm not sure why it reports two. In fact, from the nose's POV there should be just one test (Arithmetic.test) that gathers all @qc properties defined within this class. It is not ideal, of course, and I'll try to change TestCase so that it turns every property into a test case of its own.

As for your second question, the test fails for certain big/small numbers that overflow when subtracted and push the result into long type. Example:

>>> x = 4491250853479950715
>>> y = --6297086138652723899
>>> z = x - y
>>> isinstance(x, int)
True
>>> isinstance(y, int)
True
>>> isinstance(z, int)
False
>>> isinstance(z, long)
True
>>> z
10788336992132674614L

Note that addition test should fail pretty much in the same manner but because all properties are lumped together into a single test case, you cannot observe that (yet :)).

beloglazov commented 12 years ago

Great! Thank you very much for the detailed explanation!