4

I have a very simple test function that looks like this:

def test_timeout_connect():
    with pytest.raises(minus_one_rpc.TimeoutExpired):
        c = minus_one_rpc.Client("tcp://localhost:14247", recv_timeout = 100)

Without the pytest.raises(...), I am getting a FAILED test with the expected exception. However, when I try to test for the correct exception, py.test hangs at that test.

No fixtures are involved in this particular test, but it seems to have something to do with a teardown, since when I press Ctrl-C, the test is reported as SUCCESS!

test_minus_one_rpc.py::test_timeout_connect ^CPASSED

================================================== 27 tests deselected ==================================================
======================================== 1 passed, 27 deselected in 3.02 seconds ========================================

What could be the reason?

hans_meine
  • 1,881
  • 1
  • 17
  • 29
  • Insert a pdb breakpoint and step through. – jordanm May 06 '17 at 07:17
  • Thanks. I already found http://stackoverflow.com/a/26634435/1235227 to be useful, but I am *deep* in py.test then, after ~20 "finish current functions", I am at "return report" from `call_and_report()`, and when I step once more, py.test hangs. I should probably ask in the py.test issue tracker. – hans_meine May 06 '17 at 07:46

1 Answers1

1

The answer is: A destructor call that hangs.

My conclusion is that when I don't expect/catch the exception, the exc_info will hold references to the objects, preventing the destructor from running.

(In my case, I was using pyzmq with a timeout, but did not set the LINGER socket option, so the destruction of the pyzmq socket would wait for the nonexisting remote side to send something.)

hans_meine
  • 1,881
  • 1
  • 17
  • 29