diff options
author | Daniel Hahler <git@thequod.de> | 2019-04-03 21:37:27 +0200 |
---|---|---|
committer | Daniel Hahler <git@thequod.de> | 2019-04-03 22:35:18 +0200 |
commit | 757ada2fd2d0f9c5e6026f8ab2ef3c1415e1ade8 (patch) | |
tree | 1102630dbf158602338e1158c46f884c9b3d8051 /testing/test_pdb.py | |
parent | 46df1d5fcf12d3273ad5db353c68e1310916fa5f (diff) | |
download | pytest-757ada2fd2d0f9c5e6026f8ab2ef3c1415e1ade8.tar.gz |
pdb: try to import --pdbcls in pytest_configure only
Fixes https://github.com/pytest-dev/pytest/issues/5039.
Diffstat (limited to 'testing/test_pdb.py')
-rw-r--r-- | testing/test_pdb.py | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/testing/test_pdb.py b/testing/test_pdb.py index 531846e8e..61f33950d 100644 --- a/testing/test_pdb.py +++ b/testing/test_pdb.py @@ -2,7 +2,6 @@ from __future__ import absolute_import from __future__ import division from __future__ import print_function -import argparse import os import platform import sys @@ -803,13 +802,12 @@ class TestPDB(object): ) def test_pdb_validate_usepdb_cls(self, testdir): - assert _validate_usepdb_cls("os.path:dirname.__name__") == "dirname" + assert _validate_usepdb_cls("os.path:dirname.__name__") == ( + "os.path", + "dirname.__name__", + ) - with pytest.raises( - argparse.ArgumentTypeError, - match=r"^could not get pdb class for 'pdb:DoesNotExist': .*'DoesNotExist'", - ): - _validate_usepdb_cls("pdb:DoesNotExist") + assert _validate_usepdb_cls("pdb:DoesNotExist") == ("pdb", "DoesNotExist") def test_pdb_custom_cls_without_pdb(self, testdir, custom_pdb_calls): p1 = testdir.makepyfile("""xxx """) @@ -1121,3 +1119,35 @@ def test_pdb_suspends_fixture_capturing(testdir, fixture): assert child.exitstatus == 0 assert "= 1 passed in " in rest assert "> PDB continue (IO-capturing resumed for fixture %s) >" % (fixture) in rest + + +def test_pdbcls_via_local_module(testdir): + """It should be imported in pytest_configure or later only.""" + p1 = testdir.makepyfile( + """ + def test(): + print("before_settrace") + __import__("pdb").set_trace() + """, + mypdb=""" + class Wrapped: + class MyPdb: + def set_trace(self, *args): + print("mypdb_called", args) + """, + ) + result = testdir.runpytest( + str(p1), "--pdbcls=really.invalid:Value", syspathinsert=True + ) + result.stderr.fnmatch_lines( + [ + "ERROR: --pdbcls: could not import 'really.invalid:Value': No module named *really*" + ] + ) + assert result.ret == 4 + + result = testdir.runpytest( + str(p1), "--pdbcls=mypdb:Wrapped.MyPdb", syspathinsert=True + ) + assert result.ret == 0 + result.stdout.fnmatch_lines(["*mypdb_called*", "* 1 passed in *"]) |