Skip to content

Instantly share code, notes, and snippets.

@goddoe
Last active August 1, 2018 02:23
Show Gist options
  • Select an option

  • Save goddoe/a44380fde82b7c1ac1e5a508cb83a858 to your computer and use it in GitHub Desktop.

Select an option

Save goddoe/a44380fde82b7c1ac1e5a508cb83a858 to your computer and use it in GitHub Desktop.
python unittest discover

In doing a bit of digging, it seems that as long as deeper modules remain importable, they'll be discovered via python -m unittest discover. The solution, then, was simply to add a init.py file to each directory to make them packages.

.
├── LICENSE
├── models
│   └── __init__.py
├── README.md
├── requirements.txt
├── tc.py
├── tests
│   ├── db
│   │   ├── __init__.py       # NEW
│   │   └── test_employee.py
│   ├── __init__.py           # NEW
│   └── test_tc.py
└── todo.txt

So long as each directory has an init.py, python -m unittest discover can import the relevant test_* module.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment