pytest-dev / pytest-dev/pytest

pytest stuck after assertion fail

Open
#7,989 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic: fixtures type: bug
Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

Detailed Description

I'm writing pytest test cases for aiosmtpd, and I'm hitting this problem against master in aio-libs/aiosmtpd

Minimal reproducible bug as follows:

import asyncio
import pytest

from aiosmtpd.controller import Controller
from aiosmtpd.handlers import Sink
from aiosmtpd.smtp import SMTP as Server
from smtplib import SMTP


SERVER_ADDRESS = ("localhost", 8025)


def authenticator(mechanism, login, password):
    if login and login.decode() == 'goodlogin':
        return True
    else:
        return False


class DecodingController(Controller):
    def factory(self):
        return Server(self.handler, decode_data=True, enable_SMTPUTF8=True,
                      auth_require_tls=False, auth_callback=authenticator)


@pytest.fixture
def temp_loop() -> asyncio.AbstractEventLoop:
    default_loop = asyncio.get_event_loop()
    new_loop = asyncio.new_event_loop()
    asyncio.set_event_loop(new_loop)
    #
    yield new_loop
    #
    new_loop.close()
    asyncio.set_event_loop(default_loop)


@pytest.fixture
def decoding_controller(temp_loop):
    controller = DecodingController(Sink, loop=temp_loop)
    controller.start()
    temp_loop.call_later(3.0, temp_loop.stop)
    #
    print("@@@ yielding @@@")
    yield controller
    print("@@@ returning @@@")
    #
    controller.stop()


@pytest.fixture
def client():
    print(">>> entering <<<")
    with SMTP(*SERVER_ADDRESS) as smtp_client:
        yield smtp_client
    print(">>> exited <<<")


@pytest.mark.usefixtures("decoding_controller")
class TestSMTPNieuw:

    def test_data_abortconn(self, client):
        code, _ = client.helo("example.com")
        assert code == 250
        code, _ = client.docmd("MAIL FROM: <alice@example.org>")
        assert code == 250
        code, _ = client.docmd("RCPT TO: <bob@example.org>")
        assert code == 250
        print("###SENDING_DATA###")
        code, _ = client.docmd("DATA")
        assert code == 250  # I purposefully fail here
        print("###ASSERT_SUCCESS###")

Running the above inside PyCharm's Terminal window produces this:

Microsoft Windows [Version 10.0.19041.508]
(c) 2020 Microsoft Corporation. All rights reserved.

(aiosmtpd-10-cp36) C:\Repos\aiosmtpd>pytest -vvvv -s aiosmtpd\tests\test_smtp_problem.py
=========================================== test session starts ===========================================
platform win32 -- Python 3.6.8, pytest-6.1.1, py-1.9.0, pluggy-0.13.1 -- c:\repos\venvs\aiosmtpd-10-cp36\scripts\python.exe
cachedir: .pytest_cache
rootdir: C:\Repos\aiosmtpd
plugins: mock-3.3.1
collected 1 item

aiosmtpd/tests/test_smtp_problem.py::TestSMTPNieuw::test_data_abortconn @@@ yielding @@@
>>> entering <<<
###SENDING_DATA###
FAILED

... then pytest just got stuck there, not responding to anything, I can't even do Ctrl-C and I have to terminate the Terminal process.

pip list

Package            Version
------------------ -------
atomicwrites       1.4.0
atpublic           2.1.1
attrs              20.2.0
colorama           0.4.4
importlib-metadata 2.0.0
iniconfig          1.1.1
packaging          20.4
pip                20.2.4
pluggy             0.13.1
py                 1.9.0
pyparsing          2.4.7
pytest             6.1.2
pytest-mock        3.3.1
setuptools         50.3.2
six                1.15.0
toml               0.10.2
typing-extensions  3.7.4.3
zipp               3.4.0

(I actually only installed 3 packages: atpublic, pytest, and pytest-mock; the other packages are the dependencies of those three.)

pytest & OS versions

(aiosmtpd-11-cp36) C:\Repos\aiosmtpd>pytest -V
pytest 6.1.2

(aiosmtpd-11-cp36) C:\Repos\aiosmtpd>ver
Microsoft Windows [Version 10.0.19041.508]

(aiosmtpd-11-cp36) C:\Repos\aiosmtpd>python -V
Python 3.6.8

Minimal example

See "Detailed Description" above


  • a detailed description of the bug or problem you are having
  • output of pip list from the virtual environment you are using
  • pytest and operating system versions
  • minimal example if possible

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure from the minimal example in aiosmtpd/tests/test_smtp_problem.py using pytest 6.1.2 on Windows and Python 3.6.8. Start by examining the failed test's fixture teardown, especially decoding_controller and temp_loop; done means pytest exits cleanly after the assertion failure and remains interruptible.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.