pytest-dev / pytest-html

Plugin for generating HTML reports for pytest results
Other
689 stars 234 forks source link

pdbpp doesn’t works after installing this package #448

Open aminK1 opened 3 years ago

aminK1 commented 3 years ago

I have tried with a few different venv. Once I instill this package, I am not able to use breakpoint on my pytest. For debugging I use pdbpp. Please help as I would like to use this package. Pytest Version: pytest 6.2.2 pdp++ version: pdbpp 0.10.2

northernSage commented 3 years ago

Hey @aminK1 👋🏻

Conventionaly, as per pytest docs you would use the following syntax to run your tests in order to get pytest to "drop" into PDB in the event of a test failure: pytest --pdb. After testing, this seems to be working as intended with pytest-html. When it comes to explicit breakpoints, you could use the built-in breakpoint for python 3.7 and above. A simple test for reference:

# test-issue-448.py
def test_breakpoint():
    x = 12
    breakpoint()
    assert False

$> pytest --html report.html

Produces:

testing/test-issue-448.py --- PDB set_trace (IO-capturing turned off) ---

/test-issue-448.py(4)test_breakpoint() assert False (Pdb) x # << trying to check current x value 12

If you want more specific help with pdbpp, could you please provide more details? For example how you are calling the pytest command and also a minimal, reproducible example.

aminK1 commented 3 years ago

Hey @northernSage, Here is some detail and steps to reproduce the issue. pip freeze atomicwrites==1.3.0 attrs==19.3.0 boto3==1.13.25 botocore==1.16.25 certifi==2019.11.28 chardet==3.0.4 docutils==0.15.2 Faker==1.0.7 fancycompleter==0.9.1 glob2==0.7 idna==2.8 importlib-metadata==1.3.0 iniconfig==1.1.1 Jinja2==2.11.2 jmespath==0.9.4 Mako==1.1.0 MarkupSafe==1.1.1 more-itertools==8.0.2 packaging==19.2 parse==1.12.1 parse-type==0.5.2 pdbpp==0.10.2 pluggy==0.13.1 py==1.10.0 Pygments==2.9.0 PyHamcrest==1.9.0 pyparsing==2.4.5 pyral==1.4.2 pyrepl==0.9.0 pytest==6.2.4 pytest-bdd==3.2.1 pytest-html==3.1.1 pytest-metadata==1.11.0 python-dateutil==2.8.0 pytz==2019.2 requests==2.22.0 s3transfer==0.3.3 six==1.13.0 text-unidecode==1.2 toml==0.10.2 ulid-py==0.0.9 urllib3==1.25.7 wcwidth==0.1.7 wmctrl==0.4 zipp==0.6.0

command to run test pytest --pdb --html report.html

test: def test_add_two_numbers(): num1 = 44 num2 = 66 import pdb; pdb.set_trace() sum_num = num1 + num2 print(sum_num)

Please help

northernSage commented 3 years ago

I'll go ahead and reformat your example a bit to make thinks a little more clear:

import pdb

def test_add_two_numbers():
    num1 = 44
    num2 = 66
    pdb.set_trace()
    sum_num = num1 + num2
    assert sum_num == 110

You will notice that I used assert instead of print here. To understand this better I would suggest you go through pytest's getting started docs.

Unfortunately I was not able to reproduce this issue on my end. Running the above test with the following command:

pytest --html report.html --pdb

produced:

testing/test_issue_448.py ----- PDB set_trace (IO-capturing turned off) -----

/test_issue_448.py(7)test_add_two_numbers() => sum_num = num1 + num2 (Pdb) step # <<< here i stepped to check if the debugger was running properly /test_issue_448.py(8)test_add_two_numbers() => assert sum_num == 110 (Pdb) sum_num # <<< let's check sum_num value 110

As you can see, it's working as it should. One thing you could also try is dropping PDB at the start of the test using pytest --html report.html --trace. I have tested this and it also works on my end.

This does not seem to be a problem with pytest-html or pytest.

aminK1 commented 3 years ago

Hi @northernSage thank you for formatting and looking into it. I am using pdbpp to use sticky. Would you please give it a try with that?