unit tests no longer show in Test Explorer after upgrade of Visual Studio
I just upgraded from Visual Studio 15.7.x to 15.8.7. My Python unit tests no longer show in the Test Explorer. Prior to the upgrade, they showed just fine. I have done no code changes.
Here is one of my unit tests for reference:
import unittest
from util import sms_sender as sms
class TestSMS(unittest.TestCase):
'''testing sms functionality'''
def test_throw_sms_exception(self):
try:
sms.send_sms('testing sending sms to bad number', ['A1222F0X953'])
except Exception as e:
expected = "Unable to create record: The 'To' number 12220953 is not a valid phone number."
actual = e.msg
self.assertEqual(expected, actual)
Also reported at https://developercommunity.visualstudio.com/content/problem/359380/unit-tests-no-longer-show-in-test-explorer-after-u.html
Can you please confirm that they do not appear if you reload the solution? We've seen it happen regularly when discovery doesn't find any tests, and then it does on the next discovery trigger.
If it's not that, then it could be something about your code or your environment that the analyzer has trouble with.
I've replicated as much as I could from your snippet, including a package util with a mock sms_sender module with send_sms function. It was able to find the test.
Does any error appear in the output window (show output from Tests)?
Are there any crashes that appear in diagnostics logs (tools/options/python/diagnostics)?
Do you have "Use New Style IntelliSense" checked (if not, then you should) in tools/options/python/experimental?
Which version of Python are you using?
Thanks for helping get to the bottom of this.
- Can you please confirm that they do not appear if you reload the solution? We've seen it happen regularly when discovery doesn't find any tests, and then it does on the next discovery trigger.
A) I closed and reopened visual studio to reload the solution. Also rebooted. Using solution explorer I also unloaded the project and reloaded it.
- If it's not that, then it could be something about your code or your environment that the analyzer has trouble with.
A) The exact same code was discovered fine prior to the upgrade of VS.
- I've replicated as much as I could from your snippet, including a package util with a mock sms_sender module with send_sms function. It was able to find the test.
A) thanks
- Does any error appear in the output window (show output from Tests)?
A) nope. here is the output after starting VS and loading the project: [10/16/2018 5:22:37 PM Informational] ------ Discover test started ------ [10/16/2018 5:22:41 PM Informational] ========== Discover test finished: 0 found (0:00:03.4042644) ==========
here is the output if I press Run All in the test explorer:
[10/16/2018 5:12:38 PM Informational] ------ Discover test started ------ [10/16/2018 5:12:43 PM Informational] ========== Discover test finished: 0 found (0:00:04.9526723) ========== [10/16/2018 5:19:36 PM Informational] ------ Run test started ------ [10/16/2018 5:19:37 PM Informational] ========== Run test finished: 0 run (0:00:00.768327) ==========
- Are there any crashes that appear in diagnostics logs (tools/options/python/diagnostics)?
A) It has a bunch of "ImportNotFound" messages for Python files that are part of my project and load fine in VS, including the test files. But these files appear in Solution Explorer. Just to be safe I, using Solution Explorer, I excluded the test files and then included them again. Closed and opened VS to see if they get discovered. No, they did not. The ImportNotFound errors in the diagnostic files, however, are plentiful.
- Do you have "Use New Style IntelliSense" checked (if not, then you should) in tools/options/python/experimental?
A) Yes, it is and was checked.
Which version of Python are you using?
A) Python 3.6 64 bit
Thanks for the additional info.
I see ImportNotFound for items my project in my analysis logs as well, and the tests are discovered, I don't that necessarily means anything.
There were a lot of changes made to the analysis code during dev15, including in 15.8, and it is likely that a bug was introduced that affects test discovery.
We'll need a minimal repro in order to fix this.
I just took my Solution and removed all unit tests but one and removed all code but the minimum that that unit test needs. The test is still not discovered. Now we have a minimal repro. How do I get this to you?
@huguesv , I do have a repro. Please let me know how to get it to you.
Thanks!
I'm sorry, I now realized i missed your previous comment from 2 weeks ago. You can email it to us at [email protected] Thanks!
No worries. I just emailed it to you.
I'm sorry, but we haven't received it.
Can you try resending please? You can send to both ptvshelp and huvalo.
Alternatively, using the feedback tool in VS, there should be a way for you to attach more files to the bug you've already filed there (and mark them as private). I don't think you can do it via the web site, just the tool. I could be wrong, I don't use it that often myself.
@huguesv , I just re-emailed to both emails. Please let me know if you get it this time.
If this does not work, I will have to file a new bug is VS to attach, I have not found a way to attach to an existing bug in VS feedback tool.
Thank you! I just found both emails in my junk mail folder and was able to download the zip file. I'll post back when I've tried it.
On first try, it discovered test_throw_sms_exception after loading your solution. That's while debugging PTVS, on dev16.
I'll try later on release 15.8 and 15.9 preview.
On 3 similar VMs, I'm able to reproduce the issue consistently on 15.8 and 15.9 preview, but it works fine every time on 16.0 preview (not released yet).
Since this doesn't meet the bar for 15.x, we'll close this now, as it's already fixed in 16.0. Thanks for sending us the code to validate!
@huguesv, any tips on what I might want to try to get the tests discoverable?