[KED-1057] Modify the test_run.py file to be directly executable
See original GitHub issueDescription
One way of developing is to create unit tests, and then make them work. An easy way to do that is to have your unit tests runnable directly with a main entry point
Context
While using vs code, I often set my launch to a single unit test to debug whatever piece of code I am currently working on. This way, I ensure that I can work on separate concerns, and that those concerns are tested properly.
Possible Implementation
Modify the cookiecutter template project to also include :
if __name__ == "__main__":
import sys
pytest.main(sys.argv + ["--no-cov"])
at the end of test_run.py
Possible Alternatives
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
[KED-1057] Modify the test_run.py file to be directly executable
Description One way of developing is to create unit tests, and then make them work. An easy way to do that is to...
Read more >python 3.x - How to change .py to .exe - Stack Overflow
1.Install the latest version of cx_freeze by pip install cx_Freeze . 2.Create a new python file named 'setup.py' on the current ...
Read more >Testing Python in Visual Studio Code
Python tests are Python classes that reside in separate files from the code being tested. Each test framework specifies the structure and naming...
Read more >Usage and Invocations — pytest documentation
This will import pkg.testing and use its filesystem location to find and run tests from. Modifying Python traceback printing¶. Examples for modifying traceback ......
Read more >Configure unit tests by using a .runsettings file - Microsoft Learn
A common use of a .runsettings file is to customize code coverage analysis. ... To run tests from the command line, use vstest.console.exe, ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This enables me to have multiple run configuration (in vs code) to launch my test. I can simply set my run configuration to point to the unit tests of the thing I am working on, press F5, and I am debugging my code through unit tests.
There is currently no way to do that with a single keypress in vscode. According to https://code.visualstudio.com/docs/python/testing#_debug-tests, you can customize how the tests are run, but not to debug a specific file.
Essentially : I am lazy, and wants to press F5 to debug a single test file (and my code) in vscode. I have not found a way to do this yet in vscode with launch.json, except if I do the previous snippet of code. I can essentially have this launch.json file :
I don’t quite agree with point 2 I’d argue that this is a different use case than for code coverage : it is to make Test Driven Development a bit easier on the developer’s end, hence
the --no-cov
argument was added to not add to the confusion. This code does not affect howkedro run
orpytest .
works in any way, just in the case where you ask python to execute that file directly (which is kind of the point of this change)Nevertheless, I definitely agree with point 1 and 3.
Thanks for the feedback!