question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[KED-1057] Modify the test_run.py file to be directly executable

See original GitHub issue

Description

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:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
AlexandreOuelletcommented, Sep 20, 2019

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 :

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        },
        {
            "name": "Python: Test Feature X",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/src/tests/test_feature_x.py",
            "console": "integratedTerminal"
        },
        {
            "name": "Python: Test Feature Y",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/src/tests/test_feature_y.py",
            "console": "integratedTerminal"
        }
    ]
}
0reactions
AlexandreOuelletcommented, Sep 25, 2019

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 how kedro run or pytest . 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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found