Skip to content

Error running test with pytest #4334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
erihanse opened this issue Feb 8, 2019 · 16 comments
Closed

Error running test with pytest #4334

erihanse opened this issue Feb 8, 2019 · 16 comments
Labels
area-testing bug Issue identified by VS Code Team member as probable bug

Comments

@erihanse
Copy link

erihanse commented Feb 8, 2019

Issue Type: Bug

I have a simple test scenario which yields some errors in vs code. I'm trying to run the following little program with the Python extension:

import os
import shutil


def test_something():
    assert True == False


def setup_module(module):
    """ setup any state specific to the execution of the given module."""
    os.mkdir(".tmp")
    os.chdir(".tmp")


def teardown_module(module):
    """ teardown any state that was previously setup with a setup_module
    method.
    """
    os.chdir("../")
    shutil.rmtree(".tmp")

I get the following two errors:

cannot open file:///home/erikah/ok/plattform/test/test_something.py. Detail: File not found (file:///home/erikah/ok/plattform/test/test_something.py)

This path seems to be wrong, given that the path to the program is /home/erikah/ok/plattform/python_testing/test

There was an error in running the tests.
Running the test in the command line I get the following:

$ python3 -m pytest
================================================================================================================================== test session starts ===================================================================================================================================
platform linux -- Python 3.6.7, pytest-4.2.0, py-1.7.0, pluggy-0.8.1
rootdir: /home/erikah/ok/plattform/python_testing, inifile:
plugins: pylama-7.6.6
collected 1 item                                                                                                                                                                                                                                                                         

test/test_something.py F                                                                                                                                                                                                                                                           [100%]

======================================================================================================================================== FAILURES ========================================================================================================================================
_____________________________________________________________________________________________________________________________________ test_something _____________________________________________________________________________________________________________________________________

    def test_something():
>       assert True == False
E       assert True == False

../test/test_something.py:6: AssertionError
================================================================================================================================ 1 failed in 0.04 seconds ================================================================================================================================

Extension version: 2019.1.0
VS Code version: Code 1.31.0 (7c66f58312b48ed8ca4e387ebd9ffe9605332caa, 2019-02-06T08:51:24.856Z)
OS version: Linux x64 4.15.0-45-generic

System Info
Item Value
CPUs Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz (8 x 2700)
GPU Status 2d_canvas: enabled
checker_imaging: disabled_off
flash_3d: enabled
flash_stage3d: enabled
flash_stage3d_baseline: enabled
gpu_compositing: enabled
multiple_raster_threads: enabled_on
native_gpu_memory_buffers: disabled_software
rasterization: disabled_software
surface_synchronization: enabled_on
video_decode: unavailable_off
webgl: enabled
webgl2: enabled
Load (avg) 1, 1, 1
Memory (System) 31.12GB (12.10GB free)
Process Argv --unity-launch
Screen Reader no
VM 0%
@ghost ghost added the triage-needed Needs assignment to the proper sub-team label Feb 8, 2019
@erihanse
Copy link
Author

erihanse commented Feb 8, 2019

Btw., running python 3.6.7.
Another example, also failing:

import os
import shutil

import pytest

@pytest.fixture
def clean_dir():
    os.mkdir(".tmp")
    os.chdir(".tmp")
    yield
    os.chdir("../")
    shutil.rmtree(".tmp")


def test_something(clean_dir):
    assert True == False

@erihanse
Copy link
Author

erihanse commented Feb 8, 2019

Seems like I get the following when I use the command "run all unit tests".

Error: Error: Illegal value for line
I've tried disabling all extensions except for Python.

@erihanse
Copy link
Author

erihanse commented Feb 8, 2019

python_testing-1549669535148

@d3r3kk d3r3kk added the triage label Feb 11, 2019
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Feb 11, 2019
@DonJayamanne DonJayamanne added bug Issue identified by VS Code Team member as probable bug needs PR area-testing and removed triage labels Feb 20, 2019
@DonJayamanne DonJayamanne removed their assignment Feb 20, 2019
@erihanse
Copy link
Author

erihanse commented May 6, 2019

I'm still experiencing this.
image

When using fixtures, where I run tests with temporary directories for instance, this happens.

/home/erikah/ok/plattform/k8s-namespaces/k8s-namespaces/test_k8s_installer_namespace.py.
                                         ^^^^^^^^^^^^^^

@magicandcode
Copy link

magicandcode commented Nov 18, 2019

Seems like I get the following when I use the command "run all unit tests".

Error: Error: Illegal value for line
I've tried disabling all extensions except for Python.

I just ran into the same or a similar issue. Running the tests again via the tests button in the bottom status bar seems to (at least temporarily) have solved the problem.

@RomanKornev
Copy link

I'm getting the same error despite passing tests:

============================= test session starts =============================
platform win32 -- Python 3.7.4, pytest-5.2.1, py-1.8.0, pluggy-0.13.0
rootdir: c:\Users\Roman\Documents\ocr_api, inifile: pytest.ini
plugins: arraydiff-0.3, doctestplus-0.4.0, openfiles-0.4.0, remotedata-0.3.2
collected 2 items

tests\system\test_ocr.py .                                               [ 50%]
tests\system\test_server.py .                                            [100%]

- generated xml file: C:\Users\Roman\AppData\Local\Temp\tmp-24284P5KJ8aRmYqZ.xml -
============================== 2 passed in 4.76s ==============================
Error: Error: Illegal value for `line`

Bug keeps appearing and disappearing.

Log:

There was an error in running the tests.
notificationsAlerts.ts:38 Error: Illegal value for `line`
	at t.ExtHostDocumentData._lineAt (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:373:945)
	at Object.lineAt (c:\Program Files\Microsoft VS Code\resources\app\out\vs\workbench\services\extensions\node\extensionHostProcess.js:372:920)
	at f.getLocationStack (c:\Users\Roman\.vscode\extensions\ms-python.python-2020.1.57204\out\client\extension.js:75:1416606)

@sbland
Copy link

sbland commented Jul 15, 2020

I'm getting this issue too. It also seems to stop the inline error highlighting updating.

VSCode: 1.47.1
pytest version: 5.4.3
python: 3.7.5
python extension: v2020.6.91350

Python Test Log Output:

-------------- generated xml file: /tmp/tmp-3129gLnao7g2BPnx.xml ---------------
============================== 1 passed in 0.10s ===============================
Error: Error: Illegal value for `line`

I only get this if running tests using vscode. Using cli works fine.

@brettcannon
Copy link
Member

We are going through old issues and we noticed that no one from the team had replied to this issue. I want to apologize for the oversight and to let you know that the issue was reviewed by the team and triaged (as shown by the labels applied to this issue).

@Almenon
Copy link

Almenon commented Jul 29, 2020

is this issue related to #12403 by any chance?

@brettcannon
Copy link
Member

@Almenon I believe they are different issues.

@iann838
Copy link

iann838 commented Aug 21, 2020

Still experiencing in vscode:

-- Docs: https://docs.pytest.org/en/stable/warnings.html
- generated xml file: C:\Users\Spanish\AppData\Local\Temp\tmp-1396govENRcMi0AS.xml -
======================== 1 passed, 7 warnings in 5.03s ========================
Error: Error: Illegal value for `line`

python 3.8
vscode 1.48

Fixed by Re-Discovering the tests

@WilliamDidier
Copy link

Same issue :

  • Python 3.7.7 (conda)
  • VS Code 1.51.1

I believe it was caused by a test previously discovered, then commented and that was trying to be run through "Run all tests" button.
As stated in the above comment, re-descovering the tests fixed the problem.
A message a little more explicit that "Illegal value for line" would be appreciated though

@michjnich
Copy link

I'm getting this now I think, and no matter what I do I can't get it working.

In VS code I configure "Cwd" as "src", since that's where the source code for my Django project is. root dir contains all the config files, docker stuff etc.

With "src" in place, test explorer shows the tests, but they can't run. Without it, nothing is found.

If I run the tests with "src" set as cwd, I get an error telling me it couldn't find project/path/src/src/rest/of/tests/test_model.py - i.e.. the src has been applied twice somehow.

I've removed .pytest_cache, restarted VSC, rediscovered things, in every possible order, but can't get rid of this.

At the moment, I'm resorting to running my tests manually outside of VS Code. Any news on this issue?

@shacker
Copy link

shacker commented Mar 18, 2021

Just encountered the same issue. Simple test passes from Terminal, but fails with this error in VSCode. Running "Rediscover all tests" fixes it.

@rvanlaar
Copy link

I ran into the same error. The path it was searching for was wrong.
What happened was that my pycache files were originally in another directory (due to docker mounts). Removing the all the pycaches resolved the issue: find ./ -name "__pycache__" -exec rm -rf {} \+

@github-actions github-actions bot removed the needs PR label Aug 9, 2022
@karrtikr karrtikr added the needs PR Ready to be worked on label Aug 9, 2022
@eleanorjboyd
Copy link
Member

Hello! I have reviewed this issue and given the architectural changes of the testing rewrite, this issue should no longer exist on the rewrite. Therefore I am going to close this issue but please comment or open a new issue if you are still seeing a problem when you try this yourself!

To use the rewrite yourself just add ”python.experiments.optInto": ["pythonTestAdapter"] to your user settings. You can confirm you have the rewrite enabled by setting your log level to trace, via the Developer: Set Log Level command in the command palette. Then check to see if Experiment 'pythonTestAdapter' is active is in your python logs.

Thanks!

@github-actions github-actions bot removed the needs PR Ready to be worked on label Oct 30, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-testing bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests