I would like some help integrating TDD into my current projects.
My chosen TDD framework is unittest from the standard library.
My system details are: Linux Mint 17.1 64-bit, Python 3.4, bzr(for version control).

My projects are structured like:
Project > develop > Project > Project > __main__.py
                              tests   > __main__.py
I want to be able to execute my Project from a cwd of:
Project/develop/Project
as: Python3 -m Project
That currently works.
But executing my tests as: Python3 -m tests
requires that test_Project.py has this hack to import the Project module:
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
do you consider that OK? Is there a better way?
I call it a hack because every testcase file will have to have this line added to it in order to work.

I am also using coverage.py and it is good but seems to be testing the coverage of my tests, which is not desired, how can I stop this behaviour. Or is it really OK.

Output of running the tests:
python3 -m tests
Ran Main.
.
----------------------------------------------------------------------
Ran 1 test in 0.001s

OK
Name                 Stmts   Miss  Cover   Missing
--------------------------------------------------
Project/Project          3      0   100%
tests/test_Project       8      0   100%
--------------------------------------------------
TOTAL                   11      0   100%


The test files:
{FileName = __main__.py}
# -*- coding: utf-8 -*-
if __name__ == '__main__':
    import coverage
    import unittest
    cov = coverage.coverage()
    cov.start()
    # .. call your code ..
    from .test_Project import ProjectTestCase  # lint:ok
    unittest.main(exit=False)
    cov.stop()
    cov.save()
    import sys
    cov.report(file=sys.stdout)


{FileName = test_Project.py}
# -*- coding: utf-8 -*-
import os
import sys
import unittest
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
from Project import Project


class ProjectTestCase(unittest.TestCase):

    def test_example(self):
        self.assertTrue(Project.main())


The Project Files:
{FileName = __main__.py}
# -*- coding: utf-8 -*-

if __name__ == '__main__':
    from . import Project
    Project.main()

{FileName = Project.py}
# -*- coding: utf-8 -*-


def main():
    return True
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to