Question: I would like to write unit tests to test whether a dependency exists between two python packages. E.g.:

```
a/
    __init__.py
    models.py
    views.py
    ...
b/
    __init__.py
    models.py
    views.py
    ...

```

a unit test to check that modules in package `b` don't import anything from modules in package `a`. The only solution I have so far is to scan the files and check that there isn't a "from a" or "import a" in the source code. Are there other ways of doing this? One of the requirements is that `a/` and `b/` must be in the same directory level.

I would like to have this unit test because I want to be sure that I can use package `b` in other projects without package `a`, and also not have other developers write code that will make `b` dependent on `a`.

Answer: 
```
import sys
sys.modules['a'] = None

import b
# run unit tests for b to try and catch local import statements in b's functions

```
There are modules like [coverage.py](https://coverage.readthedocs.io/en/6.1.2/) that are able to check which code was executed during a test. Therefore there must be a way to check which module that code is part of which was executed during a test. This approach should work, regardless of Python's dynamic nature, contrary to what @Ben is saying in his answer.

However I'm not aware of a module that does this for you out of the box. So this sounds like a lot of manual work, but also a good possibility to release a new testing utility for this.