[TIP] New project workflow and best practices

Michael Foord fuzzyman at voidspace.org.uk
Fri Nov 26 17:46:01 PST 2010


On 11/11/2010 09:42, Gabriele Lanaro wrote:
> I started a new "almost dummy" project to test the new functionalities 
> of unittest2 but I'm encountering a lot of issues, I think because I'm 
> not finding the best practices of python testing. I'm looking for 
> suggestion on how to approach the development, here's my workflow:
>
> 1) create a directory structure and a setup script:
>
> bashpy/
>         setup.cfg
>         README
>         bashpy/
>               __init__.py
>               commands.py
>         tests/
>               __init__.py
>               test_commands.py
>
> 2) Write some functions in the bashpy.commands module, say 
> `mkdir(src)` and `rm(src)`
>
> 3) Write test classes in test_commands.py
>
> from bashpy.commands import mkdir,rm
> import unittest2 as unittest
>
> class TestRm(unittest.TestCase):
>     def test1 ...
>
> class TestCp ....
>
> 4) Run the tests
>
> from the root directory
>
> $ unit2 discover
> ... correct output from the tests ...
> ... oh! I failed TestRm.test1 !!!...
>
> 5) Run a specific test to solve problems:
> $ unit2 bashpy.tests.test_commands.TestRm.test1
> ImportError: No module named bashpy
>
> What I'm doing wrong? There's a similar linear workflow/best practices 
> used to avoid import problems etc?

Sorry for the late reply. If your package layout is as described then 
your tests aren't inside the bashpy package - they are alongside it. So 
the correct invocation for step 5 should be:

$ unit2 tests.test_commands.TestRm.test1

All the best,

Michael Foord
>
>
> _______________________________________________
> testing-in-python mailing list
> testing-in-python at lists.idyll.org
> http://lists.idyll.org/listinfo/testing-in-python


-- 

http://www.voidspace.org.uk/

READ CAREFULLY. By accepting and reading this email you agree,
on behalf of your employer, to release me from all obligations
and waivers arising from any and all NON-NEGOTIATED agreements,
licenses, terms-of-service, shrinkwrap, clickwrap, browsewrap,
confidentiality, non-disclosure, non-compete and acceptable use
policies ("BOGUS AGREEMENTS") that I have entered into with your
employer, its partners, licensors, agents and assigns, in
perpetuity, without prejudice to my ongoing rights and privileges.
You further represent that you have the authority to release me
from any BOGUS AGREEMENTS on behalf of your employer.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20101127/05971df9/attachment.htm>


More information about the testing-in-python mailing list