There are some related questions , but they do not apply.
This is my directory tree:
Β» tree abc_backend
abc_backend/
βββ backend_main.py
βββ FundDatabase.db
βββ healthcheck.py
βββ __init__.py
βββ init.py
βββ portfolio.py
βββ private.py
βββ __pycache__
βββ questionnaire.py
βββ recurring.py
βββ registration.py
βββ tests
β βββ config.py
β βββ __init__.py
β βββ __pycache__
β βββ test_backend.py
β βββ test_healthcheck.py
β βββ test_private.py
βββ trading.py
βββ Users.db
βββ VERSION
βββ visualisation.py
unittest can't find anything:
top Β» python -m unittest abc_backend
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
Not even inside abc_backend:
abc_backend Β» python -m unittest tests
----------------------------------------------------------------------
Ran 0 tests in 0.000s
OK
What I already checked:
- my test methods are correctly named (
test_whatever) - my test extensions are expanding
unittest.TestCase - directories
abc_backendand abc_backend/testshave (empty)__init__.py - all test modules are imported (see below)
unittest discover finds tests, but has problems with relative imports (see below).nose able to detect and run tests, no problem
I would like to understand:
discover unittest, ? unittest discover? ( , unittest ). :
python -m unittest python -m unittest
Β» python
Python 3.4.3 (default, Oct 14 2015, 20:28:29)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import abc_backend.tests
>>> import abc_backend.tests.test_private
>>> import abc_backend.tests.test_healthcheck
>>> import abc_backend.tests.test_backend
unittest
:
top Β» python -m unittest discover abc_backend
======================================================================
ERROR: tests.test_private (unittest.loader.ModuleImportFailure)
Traceback (most recent call last):
File "/usr/lib/python3.4/unittest/case.py", line 58, in testPartExecutor
yield
File "/usr/lib/python3.4/unittest/case.py", line 577, in run
testMethod()
File "/usr/lib/python3.4/unittest/loader.py", line 32, in testFailure
raise exception
ImportError: Failed to import test module: tests.test_private
Traceback (most recent call last):
File "/usr/lib/python3.4/unittest/loader.py", line 312, in _find_tests
module = self._get_module_from_name(name)
File "/usr/lib/python3.4/unittest/loader.py", line 290, in _get_module_from_name
__import__(name)
File "/foo/bar/abc_backend/tests/test_private.py", line 6, in <module>
from .. import init
ValueError: attempted relative import beyond top-level package
abc_backend:
abc_backend Β» python -m unittest discover tests
======================================================================
ERROR: test_private (unittest.loader.ModuleImportFailure)
Traceback (most recent call last):
File "/usr/lib/python3.4/unittest/case.py", line 58, in testPartExecutor
yield
File "/usr/lib/python3.4/unittest/case.py", line 577, in run
testMethod()
File "/usr/lib/python3.4/unittest/loader.py", line 32, in testFailure
raise exception
ImportError: Failed to import test module: test_private
Traceback (most recent call last):
File "/usr/lib/python3.4/unittest/loader.py", line 312, in _find_tests
module = self._get_module_from_name(name)
File "/usr/lib/python3.4/unittest/loader.py", line 290, in _get_module_from_name
__import__(name)
File "/foo/bar/abc_backend/tests/test_private.py", line 6, in <module>
from .. import init
SystemError: Parent module '' not loaded, cannot perform relative import