Skip to content

Python unittest error - port listening while ssh'd to server #22940

@conchoecia

Description

@conchoecia

Discussed in #22604

vscode-python version: pre-release v2024.1.10511008 (pre-release)
python version: Python 3.11.7

Hello - I am running into a similar problem to the one below while trying to use the unittest library while ssh'd into my organization's compute cluster.

I ran through the walkthrough for getting unit testing working in VScode, found here: https://code.visualstudio.com/docs/python/testing. This worked perfectly when running VScode locally on my laptop, and after fixing my python interpreter all of the tests were found just as explained in the tutorial.

When I ssh'd into my organization's compute cluster with VScode, I tried to run the same tutorial. When I run the tests, the log stops right before this line that successfully ran locally CLIENT: Server listening on port 40565... (This is the similarity to the case that I am copying below.)

Here are the last few lines of the python log after running the unit tests:

2024-02-20 16:42:27.617 [info] collected 2 items

<Module tests/test_unittest.py>
  <UnitTestCase Test_TestIncrementDecrement>
    <TestCaseFunction test_decrement>

2024-02-20 16:42:27.618 [info]     <TestCaseFunction test_increment>

2024-02-20 16:42:27.631 [info] Test server connected to a client.
2024-02-20 16:42:27.633 [info] ResultResolver EOT received for discovery.
2024-02-20 16:42:27.633 [info] 
========================== 2 tests collected in 0.15s ==========================
<<<PYTHON-EXEC-OUTPUT

2024-02-20 16:42:27.686 [info] Disposing data receiver for /<path_redacted>/dts/unittesting and deleting UUID; pytest discovery.

No tests listed, although they appear to be discovered.
Screen Shot 2024-02-20 at 4 50 03 PM

Do you think this may have something to do with my compute cluster's admin blocking specific ports from the vscode server? Is there something else I can try? I do not understand why this specifically would not work when all other functions of VScode that I have used so far work fine. Thank you, and please let me know if there is some other info to help QC.

Originally posted by dantebarba December 7, 2023
Hi

I'm dealing with an issue that I'm currently unable to resolve. The vscode language server is unable to discover the python tests from my project. This issue was quite sudden I didn't update vs code nor the python extension, it was in fact working. I've also configured the same environment in multiple platforms (debian, different versions of macos) and this never happened. I even have the same project running with pyenv in another platform and it works ok.

Current environment:

OS: 22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Nov 2 18:01:13 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

VSCode version: 1.82.3 was rolled back from latest but the issue was present on the latest versions

Python extension: 2023.10.1 also downgraded from latest to test if this was an update issue.

Python: 3.7.13 with pyenv

Troubleshooting

  • Tried deleting the .vscode and .config/Code directories and downgrading VSCode
  • Tried downgrading the extension alongside the VSCode version with all the configuration reset to defaults. The only difference here is that the error was directly displayed on test discovery instead of debug run.
  • With the latest VSCode version and extension version the tests work ok if ran without debug. The Test Results tab populates correctly with the log
  • Tried playing around with PYTHONPATH. This eventually solved the issue (adding the python path at the top of the imports in my test case): https://stackoverflow.com/questions/68584302/modulenotfounderror-no-module-named-when-trying-to-make-unit-tests-in-pyt. None of the other PYTHONPATH modification solutions worked.
import sys
sys.path.insert(0, './')

I'm also getting these first two lines now every time I debug a test that did not show up in the log before, when everything worked ok:

CLIENT: Server listening on port 40565...
Received JSON data: ['analytics_endpoints_test.AnalyticsEndpointTest.test_get_gross_revenue']

The error

2023-12-07 11:52:39.910 [info] Discover tests for workspace name: myproject - uri: /home/myuser/myproject
2023-12-07 11:52:39.910 [info] Running discovery for unittest using the new test adapter.
2023-12-07 11:52:39.910 [info] Sending discover unittest script to server.
2023-12-07 11:52:39.927 [info] Running unittests with arguments: /home/myuser/.vscode/extensions/ms-python.python-2023.10.1/pythonFiles/unittestadapter/discovery.py,--port,41847,--uuid,82406961-fb55-4b19-be45-f0b8b3f6e115,--udiscovery,-v,-s,./tests,-p,*_test.py

2023-12-07 11:52:39.927 [info] > ./venv/bin/python ~/.vscode/extensions/ms-python.python-2023.10.1/pythonFiles/unittestadapter/discovery.py --port 41847 --uuid 82406961-fb55-4b19-be45-f0b8b3f6e115 --udiscovery -v -s ./tests -p *_test.py
2023-12-07 11:52:39.927 [info] cwd: .
2023-12-07 11:52:40.051 [info] Test server connected to a client.
2023-12-07 11:52:40.052 [error] Unittest test discovery error 
 Failed to import test module: admin_endpoints_test
Traceback (most recent call last):
  File "/home/myuser/.pyenv/versions/3.7.13/lib/python3.7/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/home/myuser/.pyenv/versions/3.7.13/lib/python3.7/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/home/myuser/myproject/tests/admin_endpoints_test.py", line 8, in <module>
    from create_app import create_app
ModuleNotFoundError: No module named 'create_app'

Thanks

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions