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

Unit tests aren't discovered in sub-folders #11969

Closed
ItsDrike opened this issue May 24, 2020 · 23 comments
Closed

Unit tests aren't discovered in sub-folders #11969

ItsDrike opened this issue May 24, 2020 · 23 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster investigating We are looking into the cause of the issue

Comments

@ItsDrike
Copy link

ItsDrike commented May 24, 2020

Environment data

  • VS Code version: 1.45.1
  • Extension version (available under the Extensions sidebar): 2020.5.80290
  • OS and version: Arch Linux (kernel: linux 5.6.14.arch1-1)
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.8.3 64-bit
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): pipenv
  • Relevant/affected Python packages and their versions: unittest
  • Relevant/affected Python-related VS Code extensions and their versions: None
  • 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): True
  • Value of the python.languageServer setting: Microsoft

Actual 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 named test_decorators.py and test_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.
image

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:

  1. Create directory for tests in root of your project tests/
  2. Configure the framework to use unittests and recognise files labeled: test_*.py
  3. Add some tests in it and let the framework discover them [To this point everything is as expected]
  4. Add a subdirectory in your tests/ directory and place some other tests in it
  5. Run test discovery again
  6. No tests were found

Peek 2020-05-24 16-07

Logs

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)

[Extension Host] Info Python Extension: 2020-05-24 16:13:27: getActivatedEnvironmentVariables, Class name = E, completed in 1ms, has a truthy return value, Arg 1: <Uri:/home/itsdrike/Programming/Python/Projects/Discord-Bot>, Arg 2: undefined, Arg 3: undefined

[Extension Host] Info Python Extension: 2020-05-24 16:13:27: > ~/.local/share/virtualenvs/Discord-Bot-j5RKKR3Y/bin/python -c "import unittestloader = unittest.TestLoader()suites = loader.discover("./tests", pattern="test_*.py")print("start") #Don't remove this linefor suite in suites._tests:    for cls in suite._tests:        try:            for m in cls._tests:                print(m.id())        except:            pass"

[Extension Host] Info Python Extension: 2020-05-24 16:13:27: cwd: ~/Programming/Python/Projects/Discord-Bot

@ItsDrike ItsDrike added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels May 24, 2020
@ItsDrike
Copy link
Author

Any ideas why this is happening or what ca I do to prevent it?

@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label May 26, 2020
@ericsnowcurrently ericsnowcurrently changed the title Unit tests aren't discovered in sub-floders Unit tests aren't discovered in sub-folders May 27, 2020
@ericsnowcurrently
Copy link
Member

@ItsDrike, thanks for the report. Test discovery definitely shouldn't be behaving this way.

What happens when you run ~/.local/share/virtualenvs/Discord-Bot-j5RKKR3Y/bin/python -m unittest discover -p 'test_*.py' -t '.' -s './tests'?

(roughly equivalent to the command from the log, ~/.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())')

@ericsnowcurrently ericsnowcurrently added the info-needed Issue requires more information from poster label May 27, 2020
@ItsDrike
Copy link
Author

When I run the first command (~/.local/share/virtualenvs/Discord-Bot-j5RKKR3Y/bin/python -m unittest discover -p 'test_*.py' -t '.' -s './tests') all tests are found as seen in gif below (you can ignore that log message)

Peek 2020-05-27 21-27

but your second command has raised a SyntaxError:
image

@ericsnowcurrently
Copy link
Member

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 loader.discover() wasn't passed in the logged script. It defaults to the start dir ("./tests"), which I expect makes the tests fail. The equivalent command would be ~/.local/share/virtualenvs/Discord-Bot-j5RKKR3Y/bin/python -m unittest discover -p 'test_*.py' -s './tests' (note the missing -t arg). What happens when you run that?

@ItsDrike
Copy link
Author

Running it as multiline still produces and error, but now it's an AttributeError

image

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:

EEEEEEEEE
======================================================================
ERROR: test_names_dont_shadow (bot.cogs.test_cogs.CommandNameTests)
Names and aliases of commands should be unique.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/itsdrike/Programming/Python/Projects/Discord-Bot/tests/bot/cogs/test_cogs.py", line 70, in test_names_dont_shadow
    for cmd in self.get_all_commands():
  File "/home/itsdrike/Programming/Python/Projects/Discord-Bot/tests/bot/cogs/test_cogs.py", line 62, in get_all_commands
    for module in self.walk_modules():
  File "/home/itsdrike/Programming/Python/Projects/Discord-Bot/tests/bot/cogs/test_cogs.py", line 40, in walk_modules
    yield importlib.import_module(module.name)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/itsdrike/Programming/Python/Projects/Discord-Bot/tests/bot/cogs/test_security.py", line 6, in <module>
    from bot.cogs import security
ImportError: cannot import name 'security' from 'bot.cogs' (/home/itsdrike/Programming/Python/Projects/Discord-Bot/tests/bot/cogs/__init__.py)

======================================================================
ERROR: bot.cogs.test_security (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: bot.cogs.test_security
Traceback (most recent call last):
  File "/usr/lib/python3.8/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/home/itsdrike/Programming/Python/Projects/Discord-Bot/tests/bot/cogs/test_security.py", line 6, in <module>
    from bot.cogs import security
ImportError: cannot import name 'security' from 'bot.cogs' (/home/itsdrike/Programming/Python/Projects/Discord-Bot/tests/bot/cogs/__init__.py)


======================================================================
ERROR: bot.test_converters (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: bot.test_converters
Traceback (most recent call last):
  File "/usr/lib/python3.8/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/home/itsdrike/Programming/Python/Projects/Discord-Bot/tests/bot/test_converters.py", line 9, in <module>
    from bot.utils.converters import (
ModuleNotFoundError: No module named 'bot.utils.converters'


======================================================================
ERROR: bot.test_decorators (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: bot.test_decorators
Traceback (most recent call last):
  File "/usr/lib/python3.8/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/home/itsdrike/Programming/Python/Projects/Discord-Bot/tests/bot/test_decorators.py", line 5, in <module>
    from bot.decorators import InChannelCheckFailure, in_channel
ModuleNotFoundError: No module named 'bot.decorators'


======================================================================
ERROR: bot.test_pagination (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: bot.test_pagination
Traceback (most recent call last):
  File "/usr/lib/python3.8/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/home/itsdrike/Programming/Python/Projects/Discord-Bot/tests/bot/test_pagination.py", line 3, in <module>
    from bot import pagination
ImportError: cannot import name 'pagination' from 'bot' (/home/itsdrike/Programming/Python/Projects/Discord-Bot/tests/bot/__init__.py)


======================================================================
ERROR: bot.utils.test_checks (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: bot.utils.test_checks
Traceback (most recent call last):
  File "/usr/lib/python3.8/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/home/itsdrike/Programming/Python/Projects/Discord-Bot/tests/bot/utils/test_checks.py", line 3, in <module>
    from bot.utils import checks
ImportError: cannot import name 'checks' from 'bot.utils' (/home/itsdrike/Programming/Python/Projects/Discord-Bot/tests/bot/utils/__init__.py)


======================================================================
ERROR: bot.utils.test_time (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: bot.utils.test_time
Traceback (most recent call last):
  File "/usr/lib/python3.8/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/home/itsdrike/Programming/Python/Projects/Discord-Bot/tests/bot/utils/test_time.py", line 8, in <module>
    from bot.utils import time
ImportError: cannot import name 'time' from 'bot.utils' (/home/itsdrike/Programming/Python/Projects/Discord-Bot/tests/bot/utils/__init__.py)


======================================================================
ERROR: test_base (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: test_base
Traceback (most recent call last):
  File "/usr/lib/python3.8/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/home/itsdrike/Programming/Python/Projects/Discord-Bot/tests/test_base.py", line 6, in <module>
    from tests.base import LoggingTestsMixin, _CaptureLogHandler
  File "/home/itsdrike/Programming/Python/Projects/Discord-Bot/tests/base.py", line 9, in <module>
    from tests import helpers
  File "/home/itsdrike/Programming/Python/Projects/Discord-Bot/tests/helpers.py", line 12, in <module>
    from bot.bot import Bot
ModuleNotFoundError: No module named 'bot.bot'


======================================================================
ERROR: test_helpers (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: test_helpers
Traceback (most recent call last):
  File "/usr/lib/python3.8/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/usr/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/home/itsdrike/Programming/Python/Projects/Discord-Bot/tests/test_helpers.py", line 7, in <module>
    from tests import helpers
  File "/home/itsdrike/Programming/Python/Projects/Discord-Bot/tests/helpers.py", line 12, in <module>
    from bot.bot import Bot
ModuleNotFoundError: No module named 'bot.bot'


----------------------------------------------------------------------
Ran 9 tests in 0.003s

FAILED (errors=9)

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.

Peek 2020-05-27 23-33

@ItsDrike
Copy link
Author

So is it a bug or should I do something to fix it on my machine?

@ericsnowcurrently
Copy link
Member

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?

@ItsDrike
Copy link
Author

ItsDrike commented Jun 1, 2020

The initial output was without init, with __init__.py there, It only really says start
Peek 2020-06-01 23-36

@ericsnowcurrently
Copy link
Member

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.

@ItsDrike
Copy link
Author

ItsDrike commented Jun 1, 2020

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 __init__.py itself was created (before I clicked on reload). I'll provide a gif and some static pictures of the console log for better readability.

GIF:
Peek 2020-06-02 00-46

Pictures of the log:

image
image
image
(The highlighted log message in the last picture seems to be related.)

@ericsnowcurrently
Copy link
Member

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?

@ItsDrike
Copy link
Author

ItsDrike commented Jun 3, 2020

My full extension list with versions

arepl v1.0.24
auto-close-tag v0.5.7
autodocstring v0.5.2
better-comments v2.0.5
bracket-pair-colorizer-2 v0.1.4
code-runner v0.10.0
code-settings-sync v3.4.3
code-spell-checker v1.9.0
debug-visualizer v1.1.0
discord-vscode v3.14.0
gc-excelviewer v2.1.35
githistory v0.6.5
gitlens v10.2.1
kite v0.114.0
LiveServer v5.6.1
markdown-all-in-one v3.0.0
numbered-bookmarks v7.1.1
prettier-now v1.4.9
python v2020.5.80290
sublime-keybindings v4.0.7
todo-tree v0.0.176
vsc-community-material-theme v1.4.1
vsc-material-theme v32.6.0
vsc-material-theme-icons v1.1.4
vsc-python-indent v1.10.1
vscode-icons v10.1.1
vscode-markdownlint v0.36.0
vscode-sqlite v0.8.2
vscode-svgviewer v2.0.0
vscode-systemd-support v0.1.1
vscode-wakatime v4.0.0
vsliveshare v1.0.2236

The error log entries:

Initial tests refresh(without __init__.py)

image

Added __init__.py file (Without refreshing tests)

image

Refreshed tests (with __init__.py)

image

Full log output of console in text

VM605:1 Console was cleared
undefined
console.ts:137 [Extension Host] Info Python Extension: 2020-06-03 20:02:57: getActivatedEnvironmentVariables, Class name = E, completed in 1ms, has a truthy return value, Arg 1: <Uri:/home/itsdrike/Programming/Python/Projects/Discord-Bot>, Arg 2: undefined, Arg 3: undefined
console.ts:137 [Extension Host] Info Python Extension: 2020-06-03 20:02:57: > ~/.local/share/virtualenvs/Discord-Bot-j5RKKR3Y/bin/python -c "import unittestloader = unittest.TestLoader()suites = loader.discover("./tests", pattern="test_*.py")print("start") #Don't remove this linefor suite in suites._tests:    for cls in suite._tests:        try:            for m in cls._tests:                print(m.id())        except:            pass"
console.ts:137 [Extension Host] Info Python Extension: 2020-06-03 20:02:57: cwd: ~/Programming/Python/Projects/Discord-Bot

// This was the initial run (without __init__.py in tets/bot/ durectiry
undefined
console.ts:137 [Extension Host] No editors associated with document: /home/itsdrike/Programming/Python/Projects/Discord-Bot/tests/bot/__init__.py
t.log @ console.ts:137
$logExtensionHostMessage @ mainThreadConsole.ts:39
_doInvokeHandler @ rpcProtocol.ts:402
_invokeHandler @ rpcProtocol.ts:387
_receiveRequest @ rpcProtocol.ts:303
_receiveOneMessage @ rpcProtocol.ts:230
(anonymous) @ rpcProtocol.ts:105
fire @ event.ts:587
fire @ ipc.net.ts:453
_receiveMessage @ ipc.net.ts:733
(anonymous) @ ipc.net.ts:592
fire @ event.ts:587
acceptChunk @ ipc.net.ts:239
(anonymous) @ ipc.net.ts:200
t @ ipc.net.ts:28
emit @ events.js:203
addChunk @ _stream_readable.js:295
readableAddChunk @ _stream_readable.js:276
Readable.push @ _stream_readable.js:210
onStreamRead @ internal/stream_base_commons.js:166
mainThreadExtensionService.ts:65 [[object Object]]The "path" argument must be of type string. Received type object
$onExtensionRuntimeError @ mainThreadExtensionService.ts:65
_doInvokeHandler @ rpcProtocol.ts:402
_invokeHandler @ rpcProtocol.ts:387
_receiveRequest @ rpcProtocol.ts:303
_receiveOneMessage @ rpcProtocol.ts:230
(anonymous) @ rpcProtocol.ts:105
fire @ event.ts:587
fire @ ipc.net.ts:453
_receiveMessage @ ipc.net.ts:733
(anonymous) @ ipc.net.ts:592
fire @ event.ts:587
acceptChunk @ ipc.net.ts:239
(anonymous) @ ipc.net.ts:200
t @ ipc.net.ts:28
emit @ events.js:203
addChunk @ _stream_readable.js:295
readableAddChunk @ _stream_readable.js:276
Readable.push @ _stream_readable.js:210
onStreamRead @ internal/stream_base_commons.js:166
mainThreadExtensionService.ts:66 TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type object
	at validateString (internal/validators.js:112)
	at Object.extname (path.js:1231)
	at showNotification (/home/itsdrike/.vscode-oss/extensions/kiteco.kite-0.114.0/dist/kite-extension.js:31)
	at /home/itsdrike/.vscode-oss/extensions/kiteco.kite-0.114.0/dist/kite-extension.js:1
	at e.fire (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:46)
	at /usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:754
	at e.fire (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:46)
	at e.$acceptDocumentsAndEditorsDelta (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:651)
	at e._doInvokeHandler (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:788)
	at e._invokeHandler (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:788)
	at e._receiveRequest (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:787)
	at e._receiveOneMessage (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:785)
	at /usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:784
	at e.fire (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:46)
	at v.fire (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:232)
	at /usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:957
	at e.fire (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:46)
	at v.fire (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:232)
	at t.PersistentProtocol._receiveMessage (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:237)
	at /usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:234
	at e.fire (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:46)
	at p.acceptChunk (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:230)
	at /usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:229
	at Socket.t (/usr/lib/code/out/vs/workbench/services/extensions/node/extensionHostProcess.js:238)
	at Socket.emit (events.js:203)
	at addChunk (_stream_readable.js:295)
	at readableAddChunk (_stream_readable.js:276)
	at Socket.Readable.push (_stream_readable.js:210)
	at Pipe.onStreamRead (internal/stream_base_commons.js:166)
$onExtensionRuntimeError @ mainThreadExtensionService.ts:66
_doInvokeHandler @ rpcProtocol.ts:402
_invokeHandler @ rpcProtocol.ts:387
_receiveRequest @ rpcProtocol.ts:303
_receiveOneMessage @ rpcProtocol.ts:230
(anonymous) @ rpcProtocol.ts:105
fire @ event.ts:587
fire @ ipc.net.ts:453
_receiveMessage @ ipc.net.ts:733
(anonymous) @ ipc.net.ts:592
fire @ event.ts:587
acceptChunk @ ipc.net.ts:239
(anonymous) @ ipc.net.ts:200
t @ ipc.net.ts:28
emit @ events.js:203
addChunk @ _stream_readable.js:295
readableAddChunk @ _stream_readable.js:276
Readable.push @ _stream_readable.js:210
onStreamRead @ internal/stream_base_commons.js:166
console.ts:137 [Extension Host] Info Python Extension: 2020-06-03 20:04:02: Cached data exists getEnvironmentVariables, /home/itsdrike/Programming/Python/Projects/Discord-Bot
console.ts:137 [Extension Host] Info Python Extension: 2020-06-03 20:04:02: Cached data exists getEnvironmentVariables, /home/itsdrike/Programming/Python/Projects/Discord-Bot/tests/bot/__init__.py
console.ts:137 [Extension Host] Info Python Extension: 2020-06-03 20:04:03: > ~/.local/share/virtualenvs/Discord-Bot-j5RKKR3Y/bin/python ~/.vscode-oss/extensions/ms-python.python-2020.5.80290/pythonFiles/pyvsc-run-isolated.py flake8 --max-line-length=150 --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s ~/Programming/Python/Projects/Discord-Bot/tests/bot/__init__.py
console.ts:137 [Extension Host] Info Python Extension: 2020-06-03 20:04:03: cwd: ~/Programming/Python/Projects/Discord-Bot
console.ts:137 [Extension Host] Info Python Extension: 2020-06-03 20:04:03: > ~/.local/share/virtualenvs/Discord-Bot-j5RKKR3Y/bin/python ~/.vscode-oss/extensions/ms-python.python-2020.5.80290/pythonFiles/pyvsc-run-isolated.py flake8 --max-line-length=150 --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s ~/Programming/Python/Projects/Discord-Bot/tests/bot/__init__.py
console.ts:137 [Extension Host] Info Python Extension: 2020-06-03 20:04:03: cwd: ~/Programming/Python/Projects/Discord-Bot

// Here I added the __init__.py to tests/bot/ dir
undefined
console.ts:137 [Extension Host] Info Python Extension: 2020-06-03 20:04:30: getActivatedEnvironmentVariables, Class name = E, completed in 1ms, has a truthy return value, Arg 1: <Uri:/home/itsdrike/Programming/Python/Projects/Discord-Bot>, Arg 2: undefined, Arg 3: undefined
console.ts:137 [Extension Host] Info Python Extension: 2020-06-03 20:04:30: > ~/.local/share/virtualenvs/Discord-Bot-j5RKKR3Y/bin/python -c "import unittestloader = unittest.TestLoader()suites = loader.discover("./tests", pattern="test_*.py")print("start") #Don't remove this linefor suite in suites._tests:    for cls in suite._tests:        try:            for m in cls._tests:                print(m.id())        except:            pass"
console.ts:137 [Extension Host] Info Python Extension: 2020-06-03 20:04:30: cwd: ~/Programming/Python/Projects/Discord-Bot

// Here I refreshed tets
undefined

I've added comments after the action to describe when what thing occurred.

@ericsnowcurrently
Copy link
Member

Thanks. Do you have the problem when if you disable all the other extensions?

@ItsDrike
Copy link
Author

ItsDrike commented Jun 4, 2020

Yes the problem happens even with all extension (except Python) disabled:
Peek 2020-06-04 22-39

@ericsnowcurrently ericsnowcurrently removed the info-needed Issue requires more information from poster label Jun 8, 2020
@ItsDrike
Copy link
Author

Any progress on this?

@yhgu2000
Copy link

yhgu2000 commented Aug 1, 2020

Hi, I have the same problem with you. Exactly the same, in fact.
I assume the bug is due to that the "-t" option of unittest is not passed properly, just as you mentioned before.

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.

@karthiknadig karthiknadig added investigating We are looking into the cause of the issue and removed triage labels Sep 15, 2020
@yhgu2000
Copy link

Any progress on this?

I have came back to this page for about ten times, but nothing changed.......
This bug makes the unittest function of this plugin almost useless. I have already disable it in my projects........

@ItsDrike
Copy link
Author

ItsDrike commented Oct 24, 2020

Any progress on this?

I have came back to this page for about ten times, but nothing changed.......
This bug makes the unittest function of this plugin almost useless. I have already disable it in my projects........

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 believe I've done an okay job documenting it and providing enough details about it although I can give you more details if you need them.

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

@karrtikr
Copy link

karrtikr commented Apr 6, 2021

Is this issue still happening with the latest version of the extension?

@karrtikr karrtikr added the info-needed Issue requires more information from poster label Apr 6, 2021
@yhgu2000
Copy link

yhgu2000 commented May 11, 2021

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.

@karrtikr karrtikr removed the info-needed Issue requires more information from poster label May 11, 2021
@karrtikr
Copy link

@AtomicGu I used your sample repo but tests are discovered just fine.
image

I see the following in Python Test log output channel,

start
test_1.Test_NoImport.test_1_1
test_1.Test_NoImport.test_1_2
test_1_1 (test_1.Test_NoImport) ... ok
test_1_2 (test_1.Test_NoImport) ... ok
test_2 (unittest.loader._FailedTest) ... ERROR
NoneType: None

======================================================================
ERROR: test_2 (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: test_2
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1776.0_x64__qbz5n2kfra8p0\lib\unittest\loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1776.0_x64__qbz5n2kfra8p0\lib\unittest\loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "c:\Users\karraj\OneDrive - Microsoft\Desktop\folders\unittest_bug_example_project\package\tests\test_2.py", line 3, in <module>
    from .. import app
ImportError: attempted relative import with no known parent package


----------------------------------------------------------------------
Ran 3 tests in 0.010s

FAILED (errors=1)

Can you send the output?

@karrtikr karrtikr added the info-needed Issue requires more information from poster label Jul 28, 2021
@karrtikr
Copy link

Note we're rewriting the whole testing code with #16769, this will probably be fixed.

@karrtikr
Copy link

karrtikr commented Sep 1, 2021

Should be fixed with the new testing work. If not, please open a new issue and we'll be happy to look into it.

@karrtikr karrtikr closed this as completed Sep 1, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug info-needed Issue requires more information from poster investigating We are looking into the cause of the issue
Projects
None yet
Development

No branches or pull requests

5 participants