Great! Thanks Chamila for the detailed explanation! On Thu, Oct 23, 2014 at 3:36 PM, Chamila De Alwis <chami...@wso2.com> wrote:
> Hi Imesh, > > Python has two standard libraries for unit testing called unittest and > doctest. Doctest is a simple library which allows expressing the standard > use cases for each method in their documentation. It is not as extensive to > be used for a unit testing framework alone. 'unittest' is good but it tends > to demand some boilerplate work to be done in order to get the tests > running. And in the community the way unittest tests are written is > considered un-pythonic, since unittest is more like jUnit and is inspired > from jUnit rather than being developed from ground up for Python. These are > very useful indeed, however they tend to have a lot of rough edges in terms > of usability and extensibility. > > Py.Test[1] and Nose[2] are the two most used unit testing tools that are > built on top of the standard libraries. Out of them, Py.Test is the more > mature, extensible framework. It is also easier start working with since no > pre-configuration is needed. Both of them have the basic plugins such as > test coverage reports, mocking etc. Because of its maturity, Py.Test tends > to have more plugins and documentation resources available. Py.Test also > has a good in-built mocking component, for "monkeypatching" values from > environment variables to functions and methods. > > There is another part of Py.Test called Fixtures[3] which I'm still > investigating in to. It basically allows writing powerful setup and > teardown functions. This will hopefully help us to come up with a good > foundation for automated integration and end to end testing. > > There are other additional tools such as tox, and unittest2 which I didn't > look deep in to. They tend to be relatively new and might have few ugly > surprises down the road. > > [1] - http://pytest.org/latest/ > [2] - https://nose.readthedocs.org/en/latest/ > [3] - http://pytest.org/latest/fixture.html > > Regards, > Chamila de Alwis > Software Engineer | WSO2 | +94772207163 > Blog: code.chamiladealwis.com > > > > On Thu, Oct 23, 2014 at 1:07 AM, Imesh Gunaratne <im...@apache.org> wrote: > >> +1 A great thought Chamila, could you please provide a list of available >> python test libraries and reasons for selecting pytest? >> >> Thanks >> >> On Tue, Oct 21, 2014 at 12:47 PM, Gayan Gunarathne <gay...@wso2.com> >> wrote: >> >>> >>> +1 for pytest. I guess Nose also derived from the pytest. >>> >>> Pytest has good testing fixture mechanism which we can use to make our >>> unit test fixture. >>> >>> >>> [1] http://pytest.org/latest/xunit_setup.html#xunitsetup >>> [2] http://pytest.org/latest/fixture.html >>> >>> Thanks, >>> Gayan >>> >>> On Mon, Oct 20, 2014 at 3:55 PM, Chamila De Alwis <chami...@wso2.com> >>> wrote: >>> >>>> Hi, >>>> >>>> I started writing unit tests for the Python cartridge agent with the >>>> intention of keeping code aligned to the requirements that can change in >>>> the Java cartridge agent. >>>> >>>> I started with the Py.Test module to write and run unit tests. Py.Test >>>> is one of the most used testing libraries in Python and because of the wide >>>> spread use, a lot of handy tools are packed along with it, like test >>>> collection and reporting. There is also another library called Nose, but >>>> there seems to be a lot of online resources for Py.Test. >>>> >>>> I expect to bring up the code coverage level up to at least 60% with >>>> unit tests alone. >>>> >>>> Any inputs, suggestions? :) I think we can use Py.Test for other Python >>>> code in the Stratos project too. >>>> >>>> Regards, >>>> Chamila de Alwis >>>> Software Engineer | WSO2 | +94772207163 >>>> Blog: code.chamiladealwis.com >>>> >>>> >>>> >>> >>> >>> -- >>> >>> Gayan Gunarathne >>> Technical Lead >>> WSO2 Inc. (http://wso2.com) >>> email : gay...@wso2.com | mobile : +94 766819985 >>> >>> >> >> >> >> -- >> Imesh Gunaratne >> >> Technical Lead, WSO2 >> Committer & PMC Member, Apache Stratos >> > > -- Imesh Gunaratne Technical Lead, WSO2 Committer & PMC Member, Apache Stratos