druid-io / pydruid

A Python connector for Druid
Other
507 stars 198 forks source link

Tests unittest vs py.test #31

Closed se7entyse7en closed 8 years ago

se7entyse7en commented 8 years ago

Is there any reason for which has been choosen py.test instead of the built-in unittest for testing? I would like to add some tests and I honestly don't know py.test, but unittest seems compatible. Can I write them without using py.test?

xvrl commented 8 years ago

@se7entyse7en I believe py.test requires a lot less work to write tests than unittest, although that may have changed with unittest2 now being part of Python 2.7. I say we stick with py.test unless there is a good reason to change?

se7entyse7en commented 8 years ago

I'm not an expert about the various python testing tools, but I don't see great advantages that would let me choose py.test over the standard library unittest, but maybe just because I never used it. I took a very fast look at some other python projects to see which testing tools they use and I saw that actually projects such as flask and requests use pytest with requests using unittest and pytest for only some features. On the other hand django uses unittest. So I'm okay in using py.test.

se7entyse7en commented 8 years ago

@xvrl I found pytest-cov and I think it could be very usefull when writing tests in order to maximize the coverage of the project. Usage:

(pydruid)se7entyse7en@Marvins-MacBook-Air:~/Projects/pydruid (filtered_aggregation)$ py.test --cov-report term-missing --cov pydruid tests/
==============================================================================     test session starts     ===============================================================================
platform darwin -- Python 2.7.6 -- py-1.4.30 -- pytest-2.7.2
rootdir: /Users/se7entyse7en/Projects/pydruid, inifile: 
plugins: cov
collected 10 items 

tests/test_client.py ...s
tests/utils/test_aggregators.py ....
tests/utils/test_query_utils.py ..
---------------------------------------------------------------- coverage: platform darwin, python 2.7.6-final-0 -----------------------------------------------------------------
Name                           Stmts   Miss  Cover   Missing
------------------------------------------------------------
pydruid/__init__                   0      0   100%   
pydruid/client                   162     91    44%   112-140, 143-147, 182, 190-198, 208-209, 212-216, 251-272, 310, 365-373, 412-419, 470-478, 516-520, 546-550, 589-596
pydruid/utils/__init__             0      0   100%   
pydruid/utils/aggregators         23      0   100%   
pydruid/utils/filters             30     11    63%   30-42, 46, 49, 53, 57
pydruid/utils/having              42     20    52%   30-42, 46, 50-57, 61, 64, 67, 79, 82
pydruid/utils/postaggregator      34      9    74%   29, 33, 37, 45, 70-76
pydruid/utils/query_utils         21      1    95%   37
------------------------------------------------------------
TOTAL                            312    132    58%   

====================================================================== 9 passed, 1 skipped in 0.13 seconds     =======================================================================

We could also integrate tox in order to run tests for the different python versions and test pep8 compliancy.

xvrl commented 8 years ago

@se7entyse7en python test coverage sounds great! We could add a travis integration to get coverage stats like we do for https://github.com/druid-io/druid

se7entyse7en commented 8 years ago

@xvrl I opened the pull-request #34 starting from pull-request #32 that contains a very basic configuration for travis CI.