我有以下项目结构
- root
- main.py
- test/
- __init__.py
- conftest.py
- test.py
在conftest.py
我有一些使用mysql.connector
. 因此我正在导入:
import mysql.connector
@pytest.fixture(scope='module') # maintain connection for all tests
def cnx(database, username, password):
cnx = mysql.connector.connect(database=database, user=username, password=password)
yield cnx
cnx.close()
当我test.py
使用以下命令从根目录中的终端运行时:
pytest tests/test.py
我收到以下错误:
ImportError while loading conftest '/tests/conftest.py'.
tests/conftest.py:5: in <module>
import mysql.connector
E ModuleNotFoundError: No module named 'mysql'
为什么会这样?mysql
肯定是安装的。