Skip to content
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

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

Closed
pi-bjl opened this issue Jan 22, 2020 · 12 comments
Closed

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

pi-bjl opened this issue Jan 22, 2020 · 12 comments
Labels
area-testing bug Issue identified by VS Code Team member as probable bug

Comments

@pi-bjl
Copy link

pi-bjl commented Jan 22, 2020

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 How to update the language server to the latest stable version #3977): checked

Expected behaviour

As per pytest-dev/pytest#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.

@pi-bjl pi-bjl added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Jan 22, 2020
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Jan 22, 2020
@karthiknadig karthiknadig added triage-needed Needs assignment to the proper sub-team area-testing and removed triage-needed Needs assignment to the proper sub-team labels Jan 22, 2020
@lmilbaum
Copy link

I have tried the workaround you suggested with no avail. Can it be that pytest.ini file is ignored?

@pi-bjl
Copy link
Author

pi-bjl commented Jan 27, 2020

I have tried the workaround you suggested with no avail. Can it be that pytest.ini file is ignored?

@lioramilbaum are you sure pytest is picking it up? You can tell from the second line of output, it should look like this (in yellow):

image

I can't help you debug this further, but the pytest docs are here: https://docs.pytest.org/en/latest/customize.html#initialization-determining-rootdir-and-inifile

@memeplex
Copy link

I'm seeing the same problem, running pytest from the command line throws no warning but from inside vscode I get annoying complaints about junit.

@memeplex
Copy link

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.

@RobTheFiveNine
Copy link

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.

Thanks @memeplex - this worked for me

@dubbySwords
Copy link

Sounds very good solution. As I'm not sure which /where the configuration might be placed/called.
Can you give an indication?

@yumyai
Copy link

yumyai commented Apr 2, 2020

Sounds very good solution. As I'm not sure which /where the configuration might be placed/called.
Can you give an indication?

You can put it in .vscode/settings.json in your project

Mine looks like this

{
    "python.testing.pytestArgs": [
        "tests",
        "-s",
        "-o", "junit_family=xunit1",
    ],
    "python.testing.pytestEnabled": `true,`
}

@michaelaye
Copy link

i'm still worried about the fact that vscode doesn't find the .ini when the command line does. This sounds like not the same pytest is being run and I don't want to copy all my settings over to vscode just to make it work.

@brettcannon
Copy link
Member

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

@angelo-peronio
Copy link

I am using

  • VSCode 1.49.1
  • python extension v2020.8.109390
  • without any of the workarounds mentioned here.

I do see junit_family=xunit1 in the terminal command line invoking pytest. Could it be that this issue is solved now?

@ghost ghost added the triage-needed Needs assignment to the proper sub-team label Sep 24, 2020
@karthiknadig
Copy link
Member

This is fixed 1d15bbf

@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Sep 28, 2020
@memeplex
Copy link

Thanks!!!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 6, 2021
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
Projects
None yet
Development

No branches or pull requests

10 participants