Skip to main content

Stdout Context to use in unittest.

Project description

Karpyncho Stdout-Context

Goal

This package main goal is to extend unittest to be able to make assertions on what was printed in the console (StdOut)

Install

pip install karpyncho_stdout_context

https://pypi.org/project/stdout-stderr-capturing/

TestCaseStdoutMixin

Once the package is installed TestCaseStdoutMixin can be used along unittest.TestCase or django.test.TestCase as multiple inheritance mixin.

from unittest import TestCase

from karpyncho.stdout_context import TestCaseStdoutMixin


class TestMyClass(TestCase, TestCaseStdoutMixin):

    def test_assert_stdout_contains(self):
        with self.assertStdoutContains("xxxx"):
            print("test1")
            print("xxxx")
            print("test3")

When the context ends, the assertion will be checked

Available assertions

assertStdout(expected_output)

will assert that the context will finish writing exactly expected_output in console

assertStdoutPrints(line1, line2, ...)

is the same as assertStdout but passing each line

assertStdoutContains(*expected_output)

will assert that each string in the expected_output tuple is a substring of the console output

assertStdoutRegex(regex)

will assert that the console output matches with the provided regex

Future improvements

  • Stderr Management
  • context capturing of stdout/stderr returning the text, not forcing an assertion creating the context
  • capturing decorators

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

karpyncho-stdout-context-0.1.3.tar.gz (5.2 kB view hashes)

Uploaded Source

Built Distribution

karpyncho_stdout_context-0.1.3-py3-none-any.whl (5.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page