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.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3fa57c3c347629084067ac3d8bcf158ceb5d663a02c5614e74e77c19378a9cf8 |
|
MD5 | 85d77fee46c0aa315d2b083181112459 |
|
BLAKE2b-256 | 1c222e06e2b8809ea9d5fc787f04d271e0475be87dcc36f805deabb0e3aeea3d |
Hashes for karpyncho_stdout_context-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 997babb576b045934acec90abd471f69a577d859c116f72c0b9c04b438d83edf |
|
MD5 | e988fe66e6956983892a1de01e1f8aff |
|
BLAKE2b-256 | 2d92626d2e116705f4fc2ce2d1d4c6f8afb0d97f8d364fca9d0afb4c2b4ae125 |