I am trying to Mock an import in python for a test. My code looks something like this.
"""Python file description."""
import sys
import pytest
import datetime as dt
from unittest.mock import Mock
sys.modules['module_A'] = Mock()
from module_to_test import function_to_test
where I need to mock module_A
as a dependency for module_to_test
.
On save, VSCode auto-orders this alphabetically, and as a result creates the Mock after it tries to import from the module with the dependency.
How do I prevent the Sort Imports from ordering a subset of files? This could be through a list of files, a glob, regex or similar?
Glob pattern of the test file ./tests/test_*.py.
Update - Partial solution posted below.