Skip to content

python.testing.cwd does not work properly #11669

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
3 tasks
karrtikr opened this issue May 7, 2020 · 7 comments
Closed
3 tasks

python.testing.cwd does not work properly #11669

karrtikr opened this issue May 7, 2020 · 7 comments
Labels
area-testing bug Issue identified by VS Code Team member as probable bug regression Bug didn't exist in a previous release

Comments

@karrtikr
Copy link

karrtikr commented May 7, 2020

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.

@karrtikr karrtikr added bug Issue identified by VS Code Team member as probable bug needs PR area-testing triage-needed Needs assignment to the proper sub-team regression Bug didn't exist in a previous release labels May 7, 2020
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label May 7, 2020
@anzvanie
Copy link

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.

@karrtikr
Copy link
Author

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

@anzvanie
Copy link

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

@anzvanie
Copy link

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

@karrtikr
Copy link
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.

@karrtikr karrtikr changed the title python.testing.cwd does not work anymore python.testing.cwd does not work properly May 25, 2021
@karrtikr karrtikr changed the title python.testing.cwd does not work properly python.testing.cwd does not work properly with . May 25, 2021
@karrtikr karrtikr changed the title python.testing.cwd does not work properly with . python.testing.cwd does not work properly May 25, 2021
@b-reich
Copy link

b-reich commented Mar 12, 2022

@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?

@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

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.

@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 regression Bug didn't exist in a previous release
Projects
None yet
Development

No branches or pull requests

4 participants