vscode-python-test-adapter icon indicating copy to clipboard operation
vscode-python-test-adapter copied to clipboard

Debugging pytest with external app call

Open botsman opened this issue 6 years ago • 4 comments
trafficstars

Hello,

In my tests I need to call an external application using shell command (in my case I am calling a node application). I do it using subprocess module. So my code looks something like this:

import subprocess
def call_node():
    proc = subprocess.run(
        ['node', '-e', 'console.log(123)'],
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        timeout=30)
    return proc.stdout

def test_my_code():
    ...some logic...
    call_node()
    ...another logic...

If I execute this test from the sidebar it works fine. But if I try to debug it, I am getting an error FileNotFoundError: [Errno 2] No such file or directory: 'node': 'node'

It feels like there is some problem with environment variables (even though my node is installed globally).

I googled for some way to configure debug behavior and some people say that this might be related to a subProcess variable in my launch.json, but I didn't manage to fix it.

Is it really a bug or maybe there is a way to configure debugging to workaround my issue?

Thank you!

botsman avatar Nov 06 '19 09:11 botsman

@pbotsman Thank you for the issue! I'll take a look. In the meantime, have you tried to debug your tests with the Python extension? I'm asking because, I just would like to know if Python extension might have similar issues.

kondratyev-nv avatar Nov 07 '19 08:11 kondratyev-nv

Yes, I tried and it works fine. I am actually using python extension for debugging because I faced this issue :)

botsman avatar Nov 07 '19 08:11 botsman

@pbotsman Sorry for the wait. Unfortunately, I was not able to reproduce the issue :( However, I've changed the environment variable loading for debug configuration. These changes are in the latest published version 0.3.15. Please, update and let me know if the issue persists.

kondratyev-nv avatar Nov 27 '19 12:11 kondratyev-nv

Hi,

Thanks for trying to help me.

It looks like now I am getting a slightly different error message, but the problem is still persists for me. The error message I am getting now is Could not load source '<attrs generated init _pytest._code.code.ExceptionInfo>': Source unavailable. Such an error shows in a separate tab during debug. However I don't see the previous error message anymore.

Maybe I could provide some additional debug info for you to help understand the problem?

Also, I noticed that after I created .env file with content

PATH=${PATH}

the debugging started to work fine.

botsman avatar Nov 27 '19 13:11 botsman