How to print to console in pytest?

后端 未结 6 1582
盖世英雄少女心
盖世英雄少女心 2020-12-12 12:13

I\'m trying to use TDD (test-driven development) with pytest. pytest will not print to the console when I use print.

6条回答
  •  情歌与酒
    2020-12-12 12:31

    I originally came in here to find how to make PyTest print in VSCode's console while running/debugging the unit test from there. This can be done with the following launch.json configuration. Given .venv the virtual environment folder.

        "version": "0.2.0",
        "configurations": [
            {
                "name": "PyTest",
                "type": "python",
                "request": "launch",
                "stopOnEntry": false,
                "pythonPath": "${config:python.pythonPath}",
                "module": "pytest",
                "args": [
                    "-sv"
                ],
                "cwd": "${workspaceRoot}",
                "env": {},
                "envFile": "${workspaceRoot}/.venv",
                "debugOptions": [
                    "WaitOnAbnormalExit",
                    "WaitOnNormalExit",
                    "RedirectOutput"
                ]
            }
        ]
    }
    

提交回复
热议问题