Unittest framework suggestion in django python

  • Q: which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    • I am just sign up as a developer plan in SonarQube and I have several question and need some suggestion
  • Q: what are you trying to achieve.
    • I wonder which unit test framework is the most suitable for working along with SonarQube? Right now I am still choosing our testing framework from one of these (Django-test, python unittest, and Pytest). Each framework has its own pros and cons, I wonder what is your recommendation?
  • Q: what have you tried so far to achieve this
    • I have read the document Python Test Coverage | SonarQube Docs that using pytest can trigger the coverage test in sonarqube, I wonder how can we do it using unit-test or django-test, is that a tutorial teaching us to do that? or for now pytest is only the only option for unit-test

Hello @Zac_Lew and welcome to this community!

As far as SonarQube is concerned, there is no test framework that is particularly recommended over another.

It is true that the documentation only uses pytest as an example, since it is the most commonly used test framework. However, any framework would be supported as long as you can generate a coverage report out of it (which is the case for unittest, using Coverage.py for example).

I am personally not familiar with django-test, but I would assume it should be possible as well, and your best bet would be to go to the documentation of whichever framework you choose to use in order to generate the report, and then import it using the sonar.python.coverage.reportPaths property.

Knowing we can improve this piece of documentation, I created a small ticket so that we can make the example a bit easier to implement, and possibly provide an example for other libraries as well.

Hope that helps,

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.