-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Unit tests aren't discovered in sub-folders #11969
Comments
Any ideas why this is happening or what ca I do to prevent it? |
@ItsDrike, thanks for the report. Test discovery definitely shouldn't be behaving this way. What happens when you run (roughly equivalent to the command from the log, |
Yeah, that second command (from the log file) is actually multi-line: ~/.local/share/virtualenvs/Discord-Bot-j5RKKR3Y/bin/python -c '
import unittest
loader = unittest.TestLoader()
suites = loader.discover("./tests", pattern="test_*.py")
print("start")
for suite in suites._tests:
for cls in suite._tests:
for m in cls._tests:
print(m.id())
' The big question is if the two command actually are equivalent. I'm thinking they actually aren't. The "top_level_dir" argument to |
Running it as multiline still produces and error, but now it's an Running the `~/.local/share/virtualenvs/Discord-Bot-j5RKKR3Y/bin/python -m unittest discover -p 'test_*.py' -s './tests'` command as suggested produced very odd output:
Seems like all 9 test files were run, but and all of them resulted in an error since the required modules which were supposed to be tested weren't even found. |
So is it a bug or should I do something to fix it on my machine? |
Right. Those failures are what I would expect You should see similar output in the "Python test log" output panel. What do you see there? |
Check the console log: In the "Help" menu click "Toggle Developer Tools"; in that panel click on "Console"; look for related messages in that log. |
For some reason there was an error in the console when the file |
Thanks. That's helpful information. I don't see any reference to the Python extension's files in those stack traces. However it is hard to be sure because the paths are shortened. Would you mind pasting here the actual text of the two above error entries. That should give us the full paths. (You may also need to widen the developer tools panel first.) FWIW, the above stack trace refers to a "...kite-extension.js" where the problem happens. What other extensions do you have installed? |
My full extension list with versions
The error log entries: Full log output of console in text
I've added comments after the action to describe when what thing occurred. |
Thanks. Do you have the problem when if you disable all the other extensions? |
Any progress on this? |
Hi, I have the same problem with you. Exactly the same, in fact. I made a simple example project. The test_1 is stand-alone and can be discoverd, but the test_2 will raise an exception during import, which will cause itself undiscovered. unittest_bug_example_project.zip For now, I guess we have to code absolute imports (as the top directory was forced to ".") to use this function. |
I have came back to this page for about ten times, but nothing changed....... |
Yeah, unit-testing doesn't work at all, I think this should have higher priority than it does now since testing is a very important part of every bigger python project and it's quite rare to have all of the tests in the same directory, not detecting this automatically is a pretty big issue, why is it taking so long to fix? It's already been over 5 months since I've opened the issue and frankly, that's just unacceptable for an issue like this. I don't often push on issues being fixed, but considering it was almost half of a whole year that has already passed, I'd really appreciate it if you looked into this a little further @ericsnowcurrently |
Is this issue still happening with the latest version of the extension? |
Yes, it is. You can use this minimal reproductive project to test: unittest_bug_example_project.zip. |
Note we're rewriting the whole testing code with #16769, this will probably be fixed. |
Should be fixed with the new testing work. If not, please open a new issue and we'll be happy to look into it. |
Environment data
"python.jediEnabled"
set to; more info How to update the language server to the latest stable version #3977): Truepython.languageServer
setting: MicrosoftActual behaviour
In main
tests/
directory are some tests and some other files needed. Those work fine until a subdirectory is created, which contains 2 tests namedtest_decorators.py
andtest_pagination.py
, this subdirectory also contains the__init__.py
so that the tests can be recognized. After this subdirectory is created, the tests from main directory (tests/
) disappear and the ones from subdirectory are not displayed either, a popup saying that no tests were discovered and asking me to configure the test framework (It is configured properly)Once the
__init__.py
file is added and I rediscover the tests, this box pops up.Expected behaviour
When I add the subdirectory to main
tests/
directory and search for the tests, both the tests from my main directory and the subdirectory should be found.Steps to reproduce:
tests/
tests/
directory and place some other tests in itLogs
Output from
Console
under theDeveloper Tools
panel (toggle Developer Tools on underHelp
; turn on source maps to make any tracebacks be useful by runningEnable source map support for extension debugging
)The text was updated successfully, but these errors were encountered: