Pytest Error while Import "matplotlib.backends.backend_qt5agg" - pytest-qt

152 Views Asked by At

I have a created test file, test_sample.py. In that file I am trying to import the matplotlip package matplotlib.backends.backend_qt5agg, while running the pytest command it shows the following error. When I comment that import line, the pytest command will run successfully. But I should import that line.

test_sample.py file,

from PyQt5 import QtCore, QtGui, QtTest, QtWidgets
from PyQt5.QtCore import QCoreApplication, QObject, Qt
from PyQt5.QtWidgets import *
from pytestqt.plugin import QtBot
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas

def test_method(self):
  --------------
  all the code
  ----------------

The following error,

test_sample.py:8: in <module>
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
..\esd_env\lib\site-packages\matplotlib\backends\backend_qt5agg.py:7: in <module>
    from .backend_qtagg import (    # noqa: F401, E402 # pylint: disable=W0611
..\esd_env\lib\site-packages\matplotlib\backends\backend_qtagg.py:12: in <module>
    from .backend_qt import QtCore, QtGui, _BackendQT, FigureCanvasQT
..\esd_env\lib\site-packages\matplotlib\backends\backend_qt.py:72: in <module>
    _MODIFIER_KEYS = [
..\esd_env\lib\site-packages\matplotlib\backends\backend_qt.py:73: in <listcomp>
    (_to_int(getattr(_enum("QtCore.Qt.KeyboardModifier"), mod)),
E   TypeError: int() argument must be a string, a bytes-like object or a number, not 'KeyboardModifier'
 

I don't know why it end up with this error. This import works successfully when I run the application. It cause an error only on running testcases using commandpytest.

Note I have installed matplotlip==3.6.0

Kindly help me to fix this issue.

0

There are 0 best solutions below