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

Test run results in status bar reporting incorrect count #2143

Closed
MandarJKulkarni opened this issue Jul 12, 2018 · 9 comments · Fixed by #2383
Closed

Test run results in status bar reporting incorrect count #2143

MandarJKulkarni opened this issue Jul 12, 2018 · 9 comments · Fixed by #2383
Assignees
Labels
area-testing bug Issue identified by VS Code Team member as probable bug
Milestone

Comments

@MandarJKulkarni
Copy link

Environment data

  • VSCode Version: May 2018 (1.24)
  • Extension version (available under the Extensions sidebar): 2018.6.0
  • OS and version: Windows 10
  • Python version (& distribution if applicable, e.g. Anaconda): 2.7.14
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): NA
  • Relevant/affected Python packages and their versions: NA

Actual behavior

I use VS code for my Python projects and we have unit tests written using Python's unittest module. I am facing a weird issue with debugging unit tests.

Let's say I have 20 unit tests in a particular project.

I run the tests by right clicking on a unit test file and click 'Run all unit tests' After the run is complete, the results bar displays how many tests are passed and how many are failed. (e.g. 15 passed, 5 failed).
And I can run/debug individual test because there is a small link on every unit test function for that. If I re-run the tests from same file, then the results bar displays the twice number of tests. (e.g. 30 passed, 10 failed)
Also the links against individual test functions disappear. So I cannot run individual tests.
The only way to be able to run/debug individual tests after this is by re-launching the VS code.

Expected behavior

Re-run of unit tests should not double the number.
Individual test functions debugging should be possible.

Steps to reproduce:

Run the python tests by right clicking on a unit test file and click 'Run all unit tests'.
After the run is complete, the results bar displays how many tests are passed and how many are failed. (e.g. 15 passed, 5 failed). And you can run/debug individual test because there is a small link on every unit test function for that.
Now re-run the tests from same file, then the results bar displays the twice number of tests.

Logs

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

Starting the classic analysis engine.
##########Linting Output - pylint##########
No config file found, using default configuration


Your code has been rated at 9.95/10 (previous run: 9.72/10, +0.23)

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help)

[Extension Host] Python Extension: Error: read ECONNRESET
t.log @ workbench.main.js:sourcemap:270

@d3r3kk d3r3kk added bug Issue identified by VS Code Team member as probable bug needs verification area-testing labels Jul 12, 2018
@d3r3kk
Copy link

d3r3kk commented Jul 12, 2018

I believe I have encountered the test-count bug, but I've not seen the test 'Code Lens' disappear during testing.

@DonJayamanne
Copy link

DonJayamanne commented Jul 14, 2018

I believe I have encountered the test-count bug,

@d3r3kk please could you update the issue with instructions to replicate this.

@MandarJKulkarni
Copy link
Author

I still face this issue! For me, every time I re-run the unit tests from a file, the count doubles and 'Code Lens' (didn't know this term, nice one though!) disappears.

@DonJayamanne
Copy link

@d3r3kk @MandarJKulkarni
Please could you provide instructions along with sample code (repo) to replicate this issue.

@brettcannon brettcannon added info-needed Issue requires more information from poster needs PR and removed needs verification info-needed Issue requires more information from poster labels Jul 30, 2018
@brettcannon brettcannon added this to the Aug 2018 milestone Jul 30, 2018
@brettcannon brettcannon changed the title Issue with running Python unit tests Test run results in status bar reporting incorrect count Jul 30, 2018
@brettcannon
Copy link
Member

A reproducer thanks to @ElaineDi:

import unittest

class PassingTest(unittest.TestCase):

    def test_passing(self):
        self.assertEqual(42,42)

    def test_passing_still(self):
        self.assertEqual("silly walk", "silly walk")

class FailingTest(unittest.TestCase):

    def test_failure(self):
        self.assertEqual(42,-13)

    def test_failure_still(self):
        self.assertEqual("I'm right","No I am")

This reports 2 passes and 2 failures the first time you run all tests, 4/4 the second time.

@tmcfarlane
Copy link

+1 Reproduced this as well. Never had this issue in previous versions.

Mac OS Sierra 10.12.6
VSCode Version 1.25.1 (1.25.1)

@brettcannon brettcannon modified the milestone: Aug 2018 Aug 2, 2018
@d3r3kk d3r3kk self-assigned this Aug 9, 2018
@brettcannon brettcannon modified the milestone: Aug 2018 Aug 13, 2018
d3r3kk added a commit to d3r3kk/vscode-python that referenced this issue Aug 13, 2018
Fixes microsoft#2143

- Unregister listeners from socket service after each test run
d3r3kk added a commit to d3r3kk/vscode-python that referenced this issue Aug 13, 2018
Fixes microsoft#2143

- Unregister listeners from socket service after each test run
d3r3kk added a commit to d3r3kk/vscode-python that referenced this issue Aug 20, 2018
Fixes microsoft#2143

- Unregister listeners from socket service after each test run
@brettcannon brettcannon reopened this Aug 21, 2018
@brettcannon
Copy link
Member

I think this may have broken re-running failing tests. With the following code:

import unittest

class PassingTests(unittest.TestCase):

    def test_passing(self):
        self.assertEqual(42, 42)

    def test_passing_still(self):
        self.assertEqual("silly walk", "silly walk")


class FailingTests(unittest.TestCase):

    def test_failure(self):
        self.assertEqual(42, -13)

    def test_failure_still(self):
        self.assertEqual("I'm right!", "no, I am!")

I get the following:
example

@brettcannon
Copy link
Member

And if you run "All Tests", run just the succeeding tests through the code lens, and then run "All Tests" again, it is reported not tests ran.

In both failure cases the proper tests are actually run, the results are just reported incorrectly.

@d3r3kk
Copy link

d3r3kk commented Aug 22, 2018

Notes for tomorrow-d3r3kk:

I have found the source of the trouble. In my latest "fix", when we run tests I register all the event listeners on the server object here.

In the socket.disconnected callback I unregister everything.

This works when we are running a single file/suite/test, but it fails when we run multiple files, multiple suites (which basically amounts to files), or multiple tests, because socket.disconnect is encountered after the first file/suite/test is run and no subsequent tests will be captured!

I will rethink this design tonight and see if I cannot come up with a more useful solution (such as queue-ing up test jobs, or rethinking how we register and unregister tests).

d3r3kk added a commit to d3r3kk/vscode-python that referenced this issue Aug 22, 2018
- Add test to ensure re-running failed tests count correctly
@lock lock bot locked as resolved and limited conversation to collaborators Oct 3, 2018
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
5 participants