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
Built Distribution
Hashes for karpyncho-stdout-context-0.1.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6d298830e9bd9924abd961576b9e1c605c1b18c1eff36b34cdf9ab55c63cf1ea |
|
MD5 | 06695c03f2090b30dfb086598b8ef5a9 |
|
BLAKE2b-256 | 0297d1623d222e37b31b090f2b6e438f82f461730c28c90c6d45654e7e63b8cc |
Hashes for karpyncho_stdout_context-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7abdabd467b7c4b8699e58d76e0f9f08bc23937be12dff3e8444e3e3da1877ec |
|
MD5 | e45006463c46ee4795f36315326b5ecf |
|
BLAKE2b-256 | 5d764530123a684a561327ed94ca72e4cd73f4de9f15251c3949967d8afcbda6 |