Home > front end >  Different file paths in pyCharm and VSCode
Different file paths in pyCharm and VSCode

Time:12-29

this is my first question as I couldn't find answer to my problem. I'm developing a test automation with pytest. Most of my team is using pyCharm, but I on the other hand prefer vscode. As we created a logger, we've came up to a problem with log file location. First let me show you folder structure:

project_name
    Folder1
    Folder2
    Output
    Test
        test_case1.py
         conftest.py

Logger definition is palced in conftest.py. My coligues placed a path for a new log file to be created as shown below: ../output/logs/logger.log It works for them, but when I'm trying to run it, Python is creating output folder in other place. It's right beside project_name.

output
   Logs
Project_name
   Folder1
   etc

All I needed to do was to remove one dot ./output/logs/logger log and output folder was created correctly. I was trying to make this path Little less hardcoded, with

os.path.dirname(os.getcwd)   '\\project_name\\outpu\\logs\\logger.log

But the problem remained the same. It appears like vscode was looking from different perspective at project_name than pyCharm.

Of course I could switch to pyCharm, or force other team members to switch to vscode, but we can all agree this would be shrub solution. Is there any way to make this path cross platformish?

CodePudding user response:

Thanks to @Pavel Karateev suggestion I have managed to find the solution. Yes my colleagues were using Test as their working directory, and yes they refused to switch to main project folder.

So solution goes like this: Visual Studio Code is running from project main directory, which is stored in variable ${workspaceFolder}, to switch its current working directory, go to .vscode/settings.json and add "python.testing.cwd": '${workspaceFolder}/<directory of your choice>'.

  • Related