question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Experimental debugger wont stop on breakpoints when debugging testcases in async-await code

See original GitHub issue

Environment data

  • VS Code version: 1.25.0
  • Extension version (available under the Extensions sidebar): 2018.6.0 (20 June 2018)
  • OS and version: Kubuntu 17.10, Linux 4.13.0-46
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.6.3
  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): pipenv
  • Relevant/affected Python packages and their versions: unittest, pytest, trio, asyncio

Actual behavior

Running a test on an async function running, the debugger won’t stop on breakpoints inside async functions. Tried with both unittest and pytest. Originally tested with trio event loop but the problem also occurs with asyncio, so it is not event loop specific.

It looks as if the execution stops, but you don’t get an indication at all, no yellow line on the breakpoint, no stack trace, no variable inspection and shortly after the test seems to crash.

billede

Expected behavior

Debugger stops on breakpoint inside async function.

Steps to reproduce:

Test code using pytest:

def test_content(response):
    """Sample pytest test function with the pytest fixture as an argument."""
    # from bs4 import BeautifulSoup
    # assert 'GitHub' in BeautifulSoup(response.content).title.string
    async def test_something_async():
        assert 1 == 2

    trio.run(test_something_async)

I set the breakpoint on the assert line, like in the screenshot above.

Logs

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help)

============================= test session starts ==============================
platform linux -- Python 3.6.3, pytest-3.6.3, py-1.5.4, pluggy-0.6.0
rootdir: /home/andersa/python/realtime_data, inifile: setup.cfg

collecting 1 item                                                              
collected 1 item                                                               
tests/test_realtime_data.py 

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
anderseacommented, Jul 21, 2018

@DonJayamanne It works!

I would like to note here that if you are debugging a library, you won’t have a launch.json file, since it wouldn’t make sense to run a library, most of the time. All you want to do is run the unit tests, and be able to run the unit tests through the debugger.

For this use case you can edit the project settings file and add this configuration:

"python.unitTest.useExperimentalDebugger": true

Thanks for the help all!

1reaction
DonJayamannecommented, Jul 21, 2018

@andersea Please could you test this with the latest version of the extension. Please ensure you are using the experimental debugger. All you need to do is go into the .vscode/launch.json file and change the setting from "type":"python" to "type":"pythonExperimental"

Read more comments on GitHub >

github_iconTop Results From Across the Web

How Do I Debug Async Code in Visual Studio?
Debugging async code is challenging. Let's explore some Visual Studio tools that can help you debug your async programs easier!
Read more >
Javascript debugging with async methods is broken - YouTrack
This works as expected. When you set a breakpoint on await bar() , the breakpoint stops before 'bar' is logged. async function ...
Read more >
DevTools: console's await doesn't work when debugger is ...
The issue here is that running a microtask queue during a debug break heavily violates regular behavior of the web page. When you...
Read more >
Effective debugging with breakpoints
There are multiple types of breakpoints you can use. The most commonly used unconditional breakpoint always stops the execution when it's hit.
Read more >
Why is debugger not stopping at breakpoint after async call?
I can put a breakpoint on the await command in the executeAsync method (marked by an *) that is hit by the debugger...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found