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

unittest runner thinks failing test is not run #17561

Closed
programmerjake opened this issue Sep 29, 2021 · 6 comments · Fixed by #17578
Closed

unittest runner thinks failing test is not run #17561

programmerjake opened this issue Sep 29, 2021 · 6 comments · Fixed by #17578
Assignees
Labels
area-testing bug Issue identified by VS Code Team member as probable bug

Comments

@programmerjake
Copy link

Environment data

  • VS Code version: 1.60.2
  • Extension version (available under the Extensions sidebar): v2021.9.1246542782
  • OS and version:
    Ubuntu 20.04.3 LTS
    Linux x86_64 5.4.0-88-generic
  • Python version (& distribution if applicable, e.g. Anaconda): 3.8.10
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): venv
  • Relevant/affected Python packages and their versions: none?
  • Relevant/affected Python-related VS Code extensions and their versions: none?
  • Value of the python.languageServer setting: pylance

Expected behaviour

Reports failed test

Actual behaviour

Reports passing test/thinks test is still not run

Steps to reproduce:

Run below test using vscode:

import unittest


class Tests(unittest.TestCase):
    def test(self):
        with self.subTest():
            assert False

Logs

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

> ~/.virtualenvs/libre-riscv-venv/bin/python ~/.vscode/extensions/ms-python.python-2021.9.1246542782/pythonFiles/visualstudio_py_testlauncher.py --us=. --up=*test*.py --uvInt=2 --result-port=35131 -ttest_reproducer.Tests.test --testFile=/home/jacob/projects/libreriscv/simd_signal/test_reproducer.py
cwd: ~/projects/libreriscv/simd_signal

Output for Test Output in the Terminal panel


Running tests (unittest): /home/jacob/projects/libreriscv/simd_signal/test_reproducer.py
Running tests: [object Object]
Total number of tests expected to run: 1
Total number of tests run: 1
Total number of tests passed: 0
Total number of tests failed: 0
Total number of tests failed with errors: 0
Total number of tests skipped: 0
Finished running tests!


> Test run finished at 9/28/2021, 5:56:12 PM <

Output for Python Test Log in the Output panel

test (test_reproducer.Tests) ... 
======================================================================
FAIL: test (test_reproducer.Tests) (<subtest>)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jacob/projects/libreriscv/simd_signal/test_reproducer.py", line 7, in test
    assert False
AssertionError

----------------------------------------------------------------------
Ran 1 test in 0.000s

FAILED (failures=1)

@programmerjake programmerjake added bug Issue identified by VS Code Team member as probable bug triage-needed Needs assignment to the proper sub-team labels Sep 29, 2021
@coppinri
Copy link

This seems to be the behaviour particular to subtests.

Worse though, if the test passed previously, but now the test assertion fails, the UI still shows it as passed.
image

@karthiknadig karthiknadig self-assigned this Sep 29, 2021
@karthiknadig karthiknadig added area-testing triage and removed triage-needed Needs assignment to the proper sub-team labels Sep 29, 2021
@karthiknadig
Copy link
Member

Our test adapter for unittest, when it was written was not designed to handle unittest subtests. This is primarily due to unittest discovery cannot detect them before running the test. when subtests are used, the results are generated slightly differently from when they are not used. So we currently don't have a way to match the before subtest state.

We are in the process of re-writing the test adapter. With the redesign we will take unittest sub tests into consideration.

@karthiknadig
Copy link
Member

Related #17242

@karthiknadig
Copy link
Member

karthiknadig commented Sep 30, 2021

@programmerjake I made a PR (#17578) that addresses this issue in some form:
image

But it won't make it into up coming release. I will share the build from this PR when it is done here so you can try it out. For the code that yo shared the result should look like this:
image

@coppinri
Copy link

coppinri commented Oct 1, 2021

Wow, I was only expecting it to update the UI on a failed run, but if it's able to delve into- and report on- each subtest that would be great.

@karthiknadig
Copy link
Member

@coppinri There are limitations to this. We can only detect sub-test at run time, unittest discovery does not know about sub-tests. The subtest nodes you see above are only reporting nodes, you can specifically select them and run.

if you want to give this a try, you will need insiders version of VS Code (v 1.61.0-insider) and this build of python extensions https://github.com/microsoft/vscode-python/suites/3925208299/artifacts/98213954

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 30, 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

Successfully merging a pull request may close this issue.

3 participants