dimanche 6 mai 2018

How to run unitests of the form test/a.py?

Is it possible to implement a Python project with a file structure like the following?:

myproj
├── a.py
├── b.py
├── c.py
└── test/
    ├── a.py
    ├── b.py
    └── c.py

Note, in particular, that the test scripts under test/ have the same basenames as the module files they are testing  1. (In other words, test/a.py contains the unit tests for a.py; test/b.py contains those for b.py, etc.)

The tests under test/ all import unittest and define subclasses of unittest.TestCase.

I want to know how to run the tests under test/, both individually, and all together.

I've tried many variations of python -m unittest ..., but they all either fail (with ImportError: no module named ... error), or end up running zero tests.

(I am using Python 2.7.9.)


1 This constraint is very much intentional, and it is an integral part of the problem presented here. (IOW, a "solution" that entails relaxing this constraint is in fact not a solution.)

Aucun commentaire:

Enregistrer un commentaire