DEV Community

Sean Atukorala
Sean Atukorala

Posted on

[Solved] Pytest Error: ImportError: Error importing plugin '': No module named ...

Problem:

Running into the following error when trying to run a Pytest test suite in a Python application via the pytest command:

 File "/usr/lib/python2.7/dist-packages/_pytest/helpconfig.py", line 94, in pytest_cmdline_parse
    config = outcome.get_result()
  File "/usr/lib/python2.7/dist-packages/pluggy/callers.py", line 81, in get_result
    _reraise(*ex)  # noqa
  File "/usr/lib/python2.7/dist-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/usr/lib/python2.7/dist-packages/_pytest/config/__init__.py", line 739, in pytest_cmdline_parse
    self.parse(args)
  File "/usr/lib/python2.7/dist-packages/_pytest/config/__init__.py", line 947, in parse
    self._preparse(args, addopts=addopts)
  File "/usr/lib/python2.7/dist-packages/_pytest/config/__init__.py", line 889, in _preparse
    self.pluginmanager.consider_preparse(args)
  File "/usr/lib/python2.7/dist-packages/_pytest/config/__init__.py", line 499, in consider_preparse
    self.consider_pluginarg(parg)
  File "/usr/lib/python2.7/dist-packages/_pytest/config/__init__.py", line 524, in consider_pluginarg
    self.import_plugin(arg, consider_entry_points=True)
  File "/usr/lib/python2.7/dist-packages/_pytest/config/__init__.py", line 574, in import_plugin
    six.reraise(ImportError, new_exc, tb)
  File "/usr/lib/python2.7/dist-packages/_pytest/config/__init__.py", line 565, in import_plugin
    __import__(importspec)
ImportError: Error importing plugin "sklearn.tests.random_seed": No module named sklearn.tests.random_seed
Enter fullscreen mode Exit fullscreen mode

Solution:

There are a number of potential causes for this issue, the most likely being that the PYTHONPATH environment variable not being defined in your ~/.profile file. There are two potential solutions you can try here:

  1. Define the PYTHONPATH environment variable by running the command export PYTHONPATH=<your_user_defined_module_path_here>. Then retry running pytest
  2. Add the prefix python -m before the usual pytest command like so: python -m pytest

Conclusion

Well this is the end of the article, if you have any questions or concerns please feel free to post a comment in this article and I will get back to you if I find the time.

I hope you found this article helpful. Thanks so much for reading my article! Feel free to follow me on Twitter and GitHub, connect with me on LinkedIn and subscribe to my YouTube channel.

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay