Skip to content

Error running test with pytest #4334

Closed
Closed

Description

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%

Activity

  1. ghost added
    triage-neededNeeds assignment to the proper sub-team
    on Feb 8, 2019
  2. erihanse commented on Feb 8, 2019

    @erihanse
    Author

    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
    
  3. erihanse commented on Feb 8, 2019

    @erihanse
    Author

    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.

  4. erihanse commented on Feb 8, 2019

    @erihanse
    Author

    python_testing-1549669535148

  5. ghost removed
    triage-neededNeeds assignment to the proper sub-team
    on Feb 11, 2019
  6. erihanse commented on May 6, 2019

    @erihanse
    Author

    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.
                                             ^^^^^^^^^^^^^^
    
  7. magicandcode commented on Nov 18, 2019

    @magicandcode

    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.

  8. RomanKornev commented on Jan 10, 2020

    @RomanKornev

    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)
    
  9. 2 remaining items

  10. brettcannon commented on Jul 24, 2020

    @brettcannon
    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).

  11. Almenon commented on Jul 29, 2020

    @Almenon

    is this issue related to #12403 by any chance?

  12. brettcannon commented on Jul 29, 2020

    @brettcannon
    Member

    Almenon (@Almenon) I believe they are different issues.

  13. ianhco commented on Aug 21, 2020

    @ianhco

    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

  14. WilliamDidier commented on Jan 28, 2021

    @WilliamDidier

    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

  15. michjnich commented on Feb 10, 2021

    @michjnich

    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?

  16. shacker commented on Mar 18, 2021

    @shacker

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

  17. rvanlaar commented on May 11, 2021

    @rvanlaar

    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 {} \+

  18. eleanorjboyd commented on Oct 30, 2023

    @eleanorjboyd
    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!

  19. locked as resolved and limited conversation to collaborators on Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-testingbugIssue identified by VS Code Team member as probable bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions