Skip to content

python.unitTest.cwd no effect? #5252

Closed
Closed

Description

Issue Type: Bug

I am working on a repository with unit tests in a Tests subfolder, and the specific test needs to read a file from a subdirectory of Tests. The read fails with 'file not found', and when I print os.getcwd() before the read it reports ${workspaceFolder} regardless of what I put into python.unittest.cwd. I am using Python unittest (python.unitTest.unittestEnabled is true) framework.

Apologies if I am not understanding how this is supposed to work! Thanks

Extension version: 2019.3.6558
VS Code version: Code 1.33.1 (51b0b28134d51361cf996d2f0a1c698247aeabd8, 2019-04-11T08:22:55.268Z)
OS version: Darwin x64 18.5.0

System Info
Item Value
CPUs Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz (4 x 3200)
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: enabled
rasterization: unavailable_off
surface_synchronization: enabled_on
video_decode: enabled
webgl: enabled
webgl2: enabled
Load (avg) 2, 2, 2
Memory (System) 32.00GB (3.24GB free)
Process Argv -psn_0_4936885
Screen Reader no
VM 0%

Activity

  1. ghost added
    triage-neededNeeds assignment to the proper sub-team
    on Apr 14, 2019
  2. ghost removed
    triage-neededNeeds assignment to the proper sub-team
    on Apr 15, 2019
  3. DonJayamanne commented on Apr 15, 2019

    @DonJayamanne

    What version of python are you using?
    And are there any errors logged in the Python Test output panel.

  4. rob-miller commented on Apr 15, 2019

    @rob-miller
    Author

    Python 3.7.3
    If I hardcode the absolute dir for the file read there are no errors in the test output panel:

    test_noHstruct (test_PDB_pic.test_pic) ... /Users/rob/sync/rgithub/biopython
    ok
    
    ----------------------------------------------------------------------
    

    If I try to read from the subdir as intended (with python.unittests.cwd set to the absolute path or ${workspaceFolder}/Tests), I get:

    test_noHstruct (test_PDB_pic.test_pic) ... /Users/rob/sync/rgithub/biopython
    ERROR
    NoneType: None
    
    ======================================================================
    ERROR: test_noHstruct (test_PDB_pic.test_pic)
    
  5. DonJayamanne commented on Apr 18, 2019

    @DonJayamanne

    I'm unable to replicate this issue at my end, please could you:

    • Provide a simple sample repo or archive of the source folder with the files
    • please include the settings.json as well
  6. hvdklauw commented on May 2, 2019

    @hvdklauw

    I have the same thing with Pytest.

    Setting python.testing.cwd to ${workspaceFolder}/api then pytest reports the rootdir as the ${workspaceFolder} same with relative paths, settings it to an absolute path will work.

  7. DonJayamanne commented on May 15, 2019

    @DonJayamanne

    Got it, thanks

  8. 8 remaining items

  9. cebor commented on Dec 3, 2020

    @cebor

    I also have this issue with python.testing.unittestEnabled.

  10. Mutantpenguin commented on Sep 8, 2021

    @Mutantpenguin

    Having the same problem python.testing.unittestEnabled.

    When I enter ${workspaceFolder}/../.. into python.testing.cwd it has no effect whatsoever.

    os.getcwd() always returns my ${workspaceFolder}

  11. jaron-l commented on Sep 8, 2021

    @jaron-l

    I recently investigated this probably briefly and found that anytime that python.testing.cwd is changed, the window needs to be reloaded for the setting to be picked up. With that method, I have found that it works as expected.

  12. Mutantpenguin commented on Sep 10, 2021

    @Mutantpenguin

    Jaron (@jaron-l) Thank you very much, that worked.

    I just realized that python.testing.cwd doesn't seem to do what I expected it to do.
    It looks to my like it is used as the CWD for the test discovery too. I thought it would only be used for running the tests.

    Can anyone confirm this?

    And to make matters worse: Doesn't seem to get used when debugging a unittest.

  13. jaron-l commented on Sep 10, 2021

    @jaron-l

    It does work for test discovery too, which I'm pretty sure is intentional lest code would likely crash on discovery and not when running (or vice-versa) as you'd be running in different environments with different python paths.

    The second issue you are referencing can be found here: #8678

  14. hvdklauw commented on Sep 13, 2021

    @hvdklauw

    Funny, I tested the reloading and that did indeed fix running the tests through the Test Explorer UI and Python Test explorer (which use the python settings) but not through the normal python extension, it finds the tests, but then running the tests gives me a file or directory not found with a path relative to the workspace folder but not the testing cwd.

    This is with pytest btw.

  15. jaron-l commented on Sep 13, 2021

    @jaron-l

    Harro van der Klauw (@hvdklauw), what do you mean by "the normal python extension"? Are you talking about the CodeLens buttons? What's your workflow?

  16. hvdklauw commented on Sep 13, 2021

    @hvdklauw

    What I mean is the vscode-python test explorer, it doesn't run the tests correctly, but the Test Explorer UI (which is now deprecated but you can still use) with the python text explorer extension actually works for me, so they must be doing something right that the python extension is doing wrong, because it uses the same settings.

  17. eleanorjboyd commented on Oct 30, 2023

    @eleanorjboyd

    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!

  18. 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