question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

simple example does not seem to work

See original GitHub issue

I cannot get the simplest example to work. It is probably me not understanding what to import.

I get E ModuleNotFoundError: No module named 'pytestqt'.

Here’s the steps I did:

  1. created a python virtual environment: python3 -m venv venv
  2. activated the environment: source venv/bin/activate
  3. pip install PySide6 pytest pytest-qt
  4. created a test_hello.py (copied from doc)
from pytestqt import qtbot

def test_hello(qtbot):
    widget = HelloWidget()
    qtbot.addWidget(widget)

    # click in the Greet button and make sure it updates the appropriate label
    qtbot.mouseClick(widget.button_greet, qt_api.QtCore.Qt.MouseButton.LeftButton)

    assert widget.greet_label.text() == "Hello!"
  1. Run pytest: pytest

I expect a green pytest 1/1 success.

Instead I get this error:

% pytest
================================================================ test session starts =================================================================
platform darwin -- Python 3.9.9, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
rootdir: /nix/code/pytest-qt-example
plugins: cov-3.0.0
collected 0 items / 1 error

======================================================================= ERRORS =======================================================================
___________________________________________________________ ERROR collecting test_hello.py ___________________________________________________________
ImportError while importing test module '/nix/code/pytest-qt-example/test_hello.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/local/Cellar/python@3.9/3.9.9/Frameworks/Python.framework/Versions/3.9/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
test_hello.py:1: in <module>
    from pytestqt import qtbot
E   ModuleNotFoundError: No module named 'pytestqt'
============================================================== short test summary info ===============================================================
ERROR test_hello.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
================================================================== 1 error in 0.08s ==================================================================

I created a simple repo, if you just want to clone it and validate: https://github.com/mkinney/pytest-qt-example

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
mkinneycommented, Feb 2, 2022
1reaction
nicoddemuscommented, Feb 2, 2022

Closing for now, feel free to follow up with further questions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The best 500 seem sentence examples - YourDictionary
The most voted sentence example for seem is You never seem to study.... ... but crystals are small and usually indistinct; there is...
Read more >
Computer Basics: Basic Troubleshooting Techniques
Whenever you have a problem with your computer, don't panic! There are many basic troubleshooting techniques you can use to fix issues like...
Read more >
GTK3 Drawing area tutorial does not seem to exist?
1 Answer 1 ... You basically connect to the ::draw signal and draw in the handler using pycairo. And use queue_draw/queue_draw_area() if you...
Read more >
Logic and Mathematical Statements - Worked Examples
For this statement to be false, you can't be rich and you can't been happy. In other words, the opposite is to be...
Read more >
Non sequitur Definition & Meaning - Merriam-Webster
In Latin, non sequitur means "it does not follow." The phrase was borrowed into English in the 1500s by people who made a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found