Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DeprecationWarning: reactor.iterate cannot be used inside unit tests. In the future, using iterate will fail the test and may crash or hang the test run. #43

Open
altendky opened this issue May 20, 2020 · 2 comments

Comments

@altendky
Copy link
Member

https://github.com/pytest-dev/pytest-twisted/pull/94/checks?check_run_id=692810777

============================= test session starts ==============================
platform linux -- Python 3.6.10, pytest-5.4.2, py-1.8.1, pluggy-0.13.1 -- /__w/pytest-twisted/pytest-twisted/.tox/py36-qt5reactor/bin/python
cachedir: .pytest_cache
PyQt5 5.14.2 -- Qt runtime 5.14.2 -- Qt compiled 5.14.2
rootdir: /tmp/pytest-of-root/pytest-0/test_scrapy____something0
plugins: qt-3.3.0, xvfb-1.2.0, twisted-1.12
collecting ... collected 1 item

test_scrapy____something.py::Test::test PASSED                           [100%]

=============================== warnings summary ===============================
test_scrapy____something.py::Test::test
  /__w/pytest-twisted/pytest-twisted/.tox/py36-qt5reactor/lib/python3.6/site-packages/qt5reactor/core.py:292: DeprecationWarning: reactor.iterate cannot be used inside unit tests. In the future, using iterate will fail the test and may crash or hang the test run.
    self.iterate(delay=delay, fromqt=True)

-- Docs: https://docs.pytest.org/en/latest/warnings.html
========================= 1 passed, 1 warning in 0.10s =========================

https://github.com/sunu/qt5reactor/blob/8aaf354ef5d5ec07aca4fbe3c4ec9fba2c476ee9/src/qt5reactor/core.py#L291-L292

@altendky
Copy link
Member Author

https://github.com/twisted/twisted/blob/e17604416eadc58e90f28806968e267a06c38909/src/twisted/trial/_asynctest.py#L230-L242

    def _makeReactorMethod(self, name):
        """
        Create a method which wraps the reactor method C{name}. The new
        method issues a deprecation warning and calls the original.
        """
        def _(*a, **kw):
            warnings.warn("reactor.%s cannot be used inside unit tests. "
                          "In the future, using %s will fail the test and may "
                          "crash or hang the test run."
                          % (name, name),
                          stacklevel=2, category=DeprecationWarning)
            return self._reactorMethods[name](*a, **kw)
        return _

@altendky
Copy link
Member Author

altendky commented May 21, 2020

This was noticed over in pytest-dev/pytest-twisted#94 (for pytest-dev/pytest-twisted#93) after pytest 5.4.2 fixed (or hid or...) the other issue that related to test teardown and re-entering the reactor. I don't know if this is ... a sign of an additional pytest issue? a false alarm where this is just 'misdetected' as 'inside unit tests'? or a real qt5reactor issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant