question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

VSCode 'Run tests' for Python pytest reports warning for junit_family

See original GitHub issue

Environment data

  • VS Code version: Version: 1.41.1 (user setup) Commit: 26076a4de974ead31f97692a0d32f90d735645c0 Date: 2019-12-18T14:58:56.166Z Electron: 6.1.5 Chrome: 76.0.3809.146 Node.js: 12.4.0 V8: 7.6.303.31-electron.0 OS: Windows_NT x64 10.0.18363

  • Extension version (available under the Extensions sidebar): Name: Python Id: ms-python.python Description: Linting, Debugging (multi-threaded, remote), Intellisense, Jupyter Notebooks, code formatting, refactoring, unit tests, snippets, and more. Version: 2020.1.58038 Publisher: Microsoft VS Marketplace Link: https://marketplace.visualstudio.com/items?itemName=ms-python.python

  • OS and version: Windows_NT x64 10.0.18363

  • Python version (& distribution if applicable, e.g. Anaconda): 3.7.4

  • Type of virtual environment used (N/A | venv | virtualenv | conda | …): venv

  • Relevant/affected Python packages and their versions: pytest 5.3.2

  • Jedi or Language Server? (i.e. what is "python.jediEnabled" set to; more info #3977): checked

Expected behaviour

As per https://github.com/pytest-dev/pytest/issues/6179 , if you call pytest withOUT --junitxml, there should be no warning related to junit_family.

Actual behaviour

If I call pytest from Powershell commandline, output is as expected. However if I use ‘Run All Tests’ in VSCode, I get the following warning:

============================== warnings summary ===============================
pythonpracticevenv\lib\site-packages\_pytest\junitxml.py:436
  c:\Users\bjl\Workspace\pythonpractice\pythonpracticevenv\lib\site-packages\_pytest\junitxml.py:436: PytestDeprecationWarning: The 'junit_family' default value will change to 'xunit2' in pytest 6.0.
  Add 'junit_family=xunit1' to your pytest.ini file to keep the current format in future versions of pytest and silence this warning.
    _issue_warning_captured(deprecated.JUNIT_XML_DEFAULT_FAMILY, config.hook, 2)

-- Docs: https://docs.pytest.org/en/latest/warnings.html
- generated xml file: C:\Users\bjl\AppData\Local\Temp\tmp-18456cj6q2xypP4yi.xml -

Steps to reproduce:

[NOTE: Self-contained, minimal reproducing code samples are extremely helpful and will expedite addressing your issue]

  1. My file is just test_helloworld.py with following contents:
def helloworld(name='World'):
    return f"Hello, {name}!"

####################################################

def test_helloworld_default():
    assert helloworld() == "Hello, World"

Logs

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

> c:\Users\bjl\Workspace\pythonpractice\pythonpracticevenv\Scripts\python.exe -m pytest --rootdir c:\Users\bjl\Workspace\pythonpractice --junitxml=C:\Users\bjl\AppData\Local\Temp\tmp-18456cj6q2xypP4yi.xml tests
cwd: c:\Users\bjl\Workspace\pythonpractice

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help; turn on source maps to make any tracebacks be useful by running Enable source map support for extension debugging)

  • This instruction doesn’t make sense to me, nonetheless the source of the error is pretty obvious. VSCode is adding the --junitxml flag for its own purposes, it should also supply a value for junit_family in some unobtrusive way.

As a workaround, I will add junit_family=legacy in my own pytest.ini to silence the warning.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

10reactions
memeplexcommented, Jan 28, 2020

In order not to create additional files, and since vscode-python is the culprit here, an alternative workaround is to add:

    "python.testing.pytestArgs": [
        "-o", "junit_family=xunit1"
    ],

to your configuration file. Obviously, vscode-python should be doing this, specially because eventually the default will change and the output format may be unreadable for the extension.

2reactions
brettcannoncommented, Jul 24, 2020

We are going through old issues and we noticed that no one from the team had replied to this issue. I want to apologize for the oversight and to let you know that the issue was reviewed by the team and triaged (as shown by the labels applied to this issue).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing Python in Visual Studio Code
The Python extension supports testing with Python's built-in unittest framework and pytest. A little background on unit testing. (If you're already familiar ...
Read more >
VSCode pytest test discovery fails - python - Stack Overflow
I spent ages trying to decipher this unhelpful error after creating a test that had import errors. Verify that your test suite can...
Read more >
4.6.x PDF - pytest Documentation
23.5 Integrating with setuptools / python setup.py test / pytest-runner . ... Execute the test function with “quiet” reporting mode:.
Read more >
[WIP] How to create a modern pytest dev environment with ...
Visual Studio Code files · python.testing.pytestEnabled : enable all the pytest features if the python plugin is installed. · python.
Read more >
py.test | Python in Visual Studio Code
py.test. This section outlines the details necessary to get you up and started with using the pytest testing framework with Visual Studio Code....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found