Recursive Unittest Discovery With Python3 And Without __init__.py Files
I have project with the following directory structure: . ├── requirements.txt ├── main.py ├── tests ├── unit │ └── test_thing1.py │
Solution 1:
I looked into it, and think its most likely a bug.
So I created a python bug report and a PR which fixes the issue for me.
Clone it and see if it works for you as well, with the fix the best way of running discover was python -m unittest discover -s tests
. Otherwise it will look in for example virtual environments that are below the top dir.
Solution 2:
Note that namespace package is regular package. You must not expect namespace package is treated same to regular package.
Read this article too. https://dev.to/methane/don-t-omit-init-py-3hga
Solution 3:
Use pytest. It does discover tests in folders.
In your case you just need to install in via pip (pip install pytest
) and then run in your root folder pytest tests
.
Post a Comment for "Recursive Unittest Discovery With Python3 And Without __init__.py Files"