Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I see stdout when running Django tests?

When I run tests with ./manage.py test, whatever I send to the standard output through print doesn't show. When tests fail, I see an "stdout" block per failed test, so I guess Django traps it (but doesn't show it when tests pass).

like image 970
agentofuser Avatar asked Aug 05 '09 23:08

agentofuser


People also ask

What is Django nose?

django-nose provides all the goodness of nose in your Django tests, like: Testing just your apps by default, not all the standard ones that happen to be in INSTALLED_APPS. Running the tests in one or more specific modules (or apps, or classes, or folders, or just running a specific test)

Is Django used for Testing?

Django provides a test framework with a small hierarchy of classes that build on the Python standard unittest library. Despite the name, this test framework is suitable for both unit and integration tests. The Django framework adds API methods and tools to help test web and Django-specific behavior.

What are the best practices for testing Django apps?

In this tutorial we'll review testing best practices and example code that can be applied to any Django app. Broadly speaking there are two types of tests you need to run: Unit Tests are small, isolated, and focus on one specific function. Integration Tests are aimed at mimicking user behavior and combine multiple pieces of code and functionality.

What is unit testing in Django?

Testing is an important but often neglected part of any Django project. In this tutorial we'll review testing best practices and example code that can be applied to any Django app. Broadly speaking there are two types of tests you need to run: Unit Tests are small, isolated, and focus on one specific function.

What is testcase in Django?

Time for tests! TestCase is the most common class for writing tests in Django. It allows us to mock queries to the database. Let's test out our Post database model. With TestCase the Django test runner will create a sample test database just for our tests.

How do I write a test in Django?

The preferred way to write tests in Django is using the unittest module built-in to the Python standard library. This is covered in detail in the Writing and running tests document. You can also use any other Python test framework; Django provides an API and tools for that kind of integration.


1 Answers

Checked TEST_RUNNER in settings.py, it's using a project-specific runner that calls out to Nose. Nose has the -s option to stop it from capturing stdout, but if I run:

./manage.py test -s

manage.py captures it first and throws a "no such option" error. The help for manage.py doesn't mention this, but I found that if I run:

./manage.py test -- -s

it ignores the -s and lets me capture it on the custom runner's side, passing it to Nose without a problem.

like image 102
agentofuser Avatar answered Sep 20 '22 09:09

agentofuser