I am developing an application that it's meant to be run on linux, and relies on pty
and termios
modules (I don't think it's important, but I'm writing some DAGs on Airflow).
I use a windows workstation.
I would like to run the unit tests on my local machine, and I'm trying to use unittest.mock.patch
to prevent the import of the (non existent on my OS) modules.
Still, I have problems, and I don't know how to setup the import to avoid errors.
a minimal example is
lib.py
import termios
class C: ...
foo.py
from lib import C
def bar(): ...
test_foo.py
import foo
def test_foo_bar():
assert foo.bar() == ...
what "magic" should I write in test_foo to avoid the error
>pytest test_foo.py
============================================================================================ test session starts =============================================================================================
platform win32 -- Python 3.7.9, pytest-7.0.1, pluggy-1.0.0
rootdir: C:\Users\vito.detullio\Desktop\workspace-srm-cognitive\be-airflow-dags, configfile: pytest.ini
plugins: anyio-3.4.0, cov-3.0.0
collected 0 items / 1 error
=================================================================================================== ERRORS ===================================================================================================
_____________________________________________________________________________________ ERROR collecting delme/test_foo.py _____________________________________________________________________________________
ImportError while importing test module 'C:\Users\vito.detullio\Desktop\workspace-srm-cognitive\be-airflow-dags\delme\test_foo.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
c:\Program Files\Python37\lib\importlib\__init__.py:127: in import_module
return _bootstrap._gcd_import(name[level:], package, level)
test_foo.py:1: in <module>
import foo
foo.py:1: in <module>
from lib import C
lib.py:1: in <module>
import termios
E ModuleNotFoundError: No module named 'termios'
========================================================================================== short test summary info ===========================================================================================
ERROR test_foo.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================================================================== 1 error in 0.14s ==============================================================================================