Skip to content

python.testing.cwd does not work properly #11669

Closed

Description

@karrtikr
import unittest   # The test framework

class Test_TestIncrementDecrement1(unittest.TestCase):
    def test_increment(self):
        f = open("./demofile.txt", "r")
        print(f.read())
        self.assertEqual(2, 4)


if __name__ == '__main__':
    unittest.main()

And ./demofile.txt carrying some random content.
Set python.testing.cwd to ./Test. Run the file, it doesn't work. Setting python.testing.cwd to .\\Test works.

Activity

  1. added
    bugIssue identified by VS Code Team member as probable bug
    triage-neededNeeds assignment to the proper sub-team
    regressionBug didn't exist in a previous release
    on May 7, 2020
  2. ghost removed
    triage-neededNeeds assignment to the proper sub-team
    on May 7, 2020
  3. anzvanie commented on May 15, 2020

    @anzvanie

    The below setting is working for me with python unittest

    {
        "python.testing.cwd": "path\to\yourworkingdir",
        "python.testing.unittestArgs": [
            "-v",
            "-s",
            ".",
            "-p",
            "test_*.py"
        ],
        "python.testing.unittestEnabled": true,
    }
    

    Remember you need to restart your VSCode application after modify your settings.json file.

  4. karrtikr commented on May 15, 2020

    @karrtikr
    Author

    This issue is about having . in python.testing.cwd. Does that work for you?

  5. anzvanie commented on May 16, 2020

    @anzvanie

    I don't think having . in python.testing.cwd or not is difference.
    "python.testing.cwd": ".\\path\to\yourworkingdir" still working for me.

  6. anzvanie commented on May 18, 2020

    @anzvanie

    Kartik Raj (@karrtikr) what's way you running for test.

    If using launch.json file and run directly your file, you need to set working directory manually with cwd property

    "configurations": [
    	{
    		"name": "Python: Current File",
    		"type": "python",
    		"request": "launch",
    		"program": "${file}",
    		"console": "integratedTerminal",
    		"cwd": "${fileDirname}"
    	}
    ]
    

    You also able to using TEST EXPLORER of VSCode for testing with setting in my previous comment.
    But you will be got a problems with TEST EXPLORER of VSCode: run a test case or test class is working normally but debugging will throws an exception Unhandled exception in thread started by.

  7. karrtikr commented on May 18, 2020

    @karrtikr
    Author

    I am running the tests directly using play button, not debugging it.
    And that's not how you set debugging which is why it's throwing an error, please see #11587. If that doesn't work I recommend to open up a new issue.

  8. changed the title [-]`python.testing.cwd` does not work anymore[/-] [+]`python.testing.cwd` does not work properly[/+] on May 25, 2021
  9. changed the title [-]`python.testing.cwd` does not work properly[/-] [+]`python.testing.cwd` does not work properly with `.`[/+] on May 25, 2021
  10. changed the title [-]`python.testing.cwd` does not work properly with `.`[/-] [+]`python.testing.cwd` does not work properly[/+] on May 25, 2021
  11. b-reich commented on Mar 12, 2022

    @b-reich

    Kartik Raj (@karrtikr) what's way you running for test.

    If using launch.json file and run directly your file, you need to set working directory manually with cwd property

    "configurations": [
    	{
    		"name": "Python: Current File",
    		"type": "python",
    		"request": "launch",
    		"program": "${file}",
    		"console": "integratedTerminal",
    		"cwd": "${fileDirname}"
    	}
    ]
    

    You also able to using TEST EXPLORER of VSCode for testing with setting in my previous comment. But you will be got a problems with TEST EXPLORER of VSCode: run a test case or test class is working normally but debugging will throws an exception Unhandled exception in thread started by.

    This launchfile doesnt work for me anymore... Do you have the same problem?

  12. eleanorjboyd commented on Oct 30, 2023

    @eleanorjboyd

    everything works in this issue except: "need to reload window everytime for changes in the setting to take effect". Will create another issue about this specifically but all other aspects of this issue are resolved.

  13. 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 bugregressionBug didn't exist in a previous release

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions