forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
When running dynamically generated tests for module, only the first one runs #4593
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
Labels
Comments
Similar to #4567 |
No, its not the same as #4567 |
Thanks for letting us know about this, @alexvy86. I've been able to reproduce the problem using the file you provided: import unittest
class TestClass(unittest.TestCase):
pass
def make_dynamic_test_function(text: str):
def test_function(self):
self.assertEqual(text, "Correct")
return test_function
test_parameters = [
"Incorrect",
"Correct",
]
for item in test_parameters:
setattr(TestClass,
f"test_text__{item}",
make_dynamic_test_function(item)) We'll work on fixing this. |
I saw that today's release of the extension included a fix for #4567 so I decided to give this another try, and it works now! So maybe they were indeed the same thing :). Closing the issue. |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Environment data
Expected behaviour
All dynamically generated test (
unittest
) methods within a module/file should run when clicking the "Run test" button for that module/file in test explorer, or when using the context menu and selecting "Run current unit test file".Note that this is already the case when clicking the "Run test" button for the class inside the module/file, in test explorer.
Actual behaviour
When clicking the "Run test" button for the module/file in the test explorer, or when selecting "Run current unit test file" from the context menu, only the first dynamically generated test method runs.
As mentioned above, when clicking the "Run test" button for the class inside the module/file, in the test explorer, then all the dynamically generated tests run fine.
Steps to reproduce:
See the screen capture below with a reproduction. The overall idea is to create a (
unittest
) test class and generate its test methods dynamically withsetattr
, then try to run the resulting set of tests. In the screen capture I dynamically generate two tests. I first run the tests for the class (through test explorer), and both generated tests run fine. Then I run them for the file (through test explorer) and only the first one runs. Finally I run them with the context menu and "Run current unit test file" and again only the first one runs.The project in the screen capture can be found in this branch.
Logs
Output for
Python
in theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toPython
)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 following set of messages show up for any of the 3 test cases described above (run module in test explorer, run class in test explorer, run tests in current file from context menu).
The text was updated successfully, but these errors were encountered: