Python Unit test debugging in VS code - python

I use VS code for my Python projects and we have unit tests written using Python's unittest module. I am facing a weird issue with debugging unit tests.
VSCode Version: May 2018 (1.24)
OS Version: Windows 10
Let's say I have 20 unit tests in a particular project.
I run the tests by right clicking on a unit test file and click 'Run all unit tests'
After the run is complete, the results bar displays how many tests are passed and how many are failed. (e.g. 15 passed, 5 failed).
And I can run/debug individual test because there is a small link on every unit test function for that.
If I re-run the tests from same file, then the results bar displays the twice number of tests. (e.g. 30 passed, 10 failed)
Also the links against individual test functions disappear. So I cannot run individual tests.
The only way to be able to run/debug individual tests after this is by re-launching the VS code.
Any suggestions on how to fix this?

If anyone is still facing issue related to Unit Test debug and Run related issue in VS Code for Linux or Windows. Please follow these two steps.
Download Latest Build From VSCode Repo Download Ling It will download a .vsix file which is an official extension to be added into next release.
Install the downloaded extension (.vsix) by using command code --install-extension myextension.vsix For more detail Read This How to install Click Here
I also faced a lot of issues and struggled a lot. So finally I raised an issue in the official GitHub repository. Check here Which helped me to solve the issue.

This was a bug in Python extension for VS code and it is fixed now.

Related

How to force Pycharm to not use .egg code version?

I'm newbie to pycharm so not sure if this is a common problem or not.
Whenever I debug a code with break points or run a code (for example unit tests code), pycharm is directly accessing the .egg version of my code which is usually different than the actual code version.
Is there a way to fix this problem?

Is there an example of PyFlink SQL unit testing in a self-contained repo?

Is there an example of a self-contained repository showing how to perform SQL unit testing of PyFlink (specifically 1.13.x if possible)?
There is a related SO question here, where it is suggested to use some of the tests from PyFlink itself. The issue I'm running into is that the PyFlink repo assumes that a bunch of things are on the Java classpath and that some Python utility classes are available (they're not distributed via PyPi apache-flink).
I have done the following:
Copied test_case_utils.py and source_sink_utils.py from PyFlink into my project.
Copy an example unit test (this one as suggested by the related SO question.
When I try to run the test, I get an error because the test case cannot determine what version of Avro jars to download (download_apache_avro() fails, because this code tries to evaluate the value of avro.version by running mvn help:evaluate -Dexpression=avro.version)
I then added a dummy pom.xml defining a Maven property of avro.version (with a value of 1.10.0) and my unit test case is loaded.
I now get a new error and my test is skipped:
'flink-table-planner*-tests.jar' is not available. Will skip the related tests.
I don't know how to fix this. I've tried adding flink-table-planner and flink-table-planner-blink dependencies with <type>test-jar</type> to my dummy pom.xml, but it still fails.
This is starting to feel like a real pain to do something that should be trivial: basic TDD of a PyFlink project. Is there a real-world example of a Python project that shows how to set up a testing environment for unit testing SQL with PyFlink?
You can refer to https://github.com/dianfu/pyflink-faq/tree/main/testing which gives an example on how to write unit tests in an external project.

Lego EV3 python intellisense not available?

I've gone through the steps to get started with Lego EV3 and python described here: https://education.lego.com/en-us/support/mindstorms-ev3/python-for-ev3 however visual studio code isn't giving me any intellisense into pybricks.
In order to get anything up and running I'm having to constantly reference the pdf documentation. While that isn't an issue for me personally (2 monitors), it will be come this September when I'm trying to teach a class of 4-6 grade kids how to code on small laptops.
The root of the issue is that deploying the application involves copying all the files onto the robot where pybricks is present and all the imports actually work. However locally in VSCode none of the imports work properly so there's no autocomplete magic.
Anyone know the best solution for getting autocomplete/intellisense up and working?
You have to install python-ev3dev2 package.
You can check the description at the end of this page:
https://github.com/ev3dev/vscode-hello-python
You will either need the source code or you could write .pyi files -- which are basically just typed stub files -- to provide the typing information.
As of 2019, simply installing pybrick stubs did the job for me:
$ pip install pybrick-stubs

Python - Difference between Sonarcube Vs pylint

I'm evaluating test framework, lint and code coverage options for a new Python project I'll be working on.
I've chosen pytest for the testing needs. After reading a bunch of resources, I'm confused when to use Sonarcube, Sonarlint , pylint and coverage.py.
Is SonarLint and Pylint comparable? When would I use Sonarcube?
I need to be able to use this in a Jenkins build. Thanks for helping!
Sonarlint and pylint are comparable, in a way.
Sonarlint is a code linter and pylint is too. I haven't used sonarlint, but it seems that analyzes the code a bit deeper that pylint does. From my experience, pylint only follows a set of rules (that you can modify, by the way), while sonarlint goes a bit further analyzing the inner workings of your code. They are both static analyze tools, however.
Sonarcube, on the other hand, does a bit more. Sonarcube is a CI/CD tool that runs static linters, but also shows you code smells, and does a security analysis. All of what I'm saying is based purely on their website.
If you would like to run CI/CD workflows or scripts, you would use Sonarcube, but for local coding, sonarlint is enough. Pylint is the traditional way, though.
Nicholas has a great summary of Pylint vs Sonarlint.
(Personally I use the Sonarlint)
Although the question is older, I thought I'd answer the other part of your question in case anyone else has the same question; internet being eternal and all.
Coverage.py as it sounds, runs code coverage for your package. SonarQube then uses the report that coverage.py makes and does things with it and formats it in a way that the Sonar team decided was necessary. Coverage.py is needed if you want to use SonarQube for code coverage. However, if you just want the code smells from SonarQube, it is not needed.
You were also asking about when to use SonarQube, coverage.py, and Jenkins.
In Jenkins, you would create a pipeline with several stages. Something along the following lines:
Check out code (automatically done as the first step by Jenkins
Build code as it is intended to be used by user/developer
Run Unit Tests
run coverage.py
run SonarQube

Python Tools for Visual Studio and Unit Tests (PTVS)

Hopefully someone can give me a hand/few pointers.
So I am currently working on some python scripts and wanted to get some tests written.
My environment is as follows:
MS Visual Studio Community 2015, v.14 Update 3
PTVS v.2.2.4 (2.2.40623.00-14.0)
Python 3.5 64-bit Environment
I have some demo tests written in a test class, which have been appearing and disappearing in test explorer under their own will. Currently, I have none showing in Test Explorer, as per the screenshot below...
Several other people seem to be having issues, and the reasons vary from the test settings processor architecture selected, through to clearing the files in the temp folder etc.
I have been pulling out my hair for a few days now, and am looking for your help, cos i'm now bald.
I've tried removing PTVS and reinstalling, updating to latest, changing the test environment, adding and removing Nunit, incase that was conflicting, etc etc etc.
Any help would be greatly appreciated.
Just managed to get this error message to appear, but I do not think it's correct:
OK, so another update:
I decided that I would download VS CE 2013, and then install PTVS 2.2.3.
I opened the solution there, and the tests loaded instantly, and ran first time...
I know that is not a solution to the problem, but at least I can now run my tests and continue working.
Kindest Regards,
Ok, so it seems that PTVS does not fully work with VS2015 Community Edition.
You can run your scripts etc, but it does not integrate with the test explorer properly.
You will need to download VS2013 CE, and PTVS 2.2.2. Then you can run the test explorer and click run all, which will find all your tests, and run properly. Hope this helps someone, as I spent days trying to get VS2015 and PTVS 2.2.4 working with no luck.

Categories

Resources