Skip to content

Commit

Permalink
Added conftest.py (demisto#17795)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShacharKidor authored Feb 21, 2022
1 parent ffb8463 commit 9dec920
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions Tests/scripts/dev_envs/pytest/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import pytest
import logging


# File is copied to each package dir when running tests.
# More info about conftest.py at:
# https://docs.pytest.org/en/latest/writing_plugins.html#conftest-py-plugins # disable-secrets-detection


@pytest.fixture(autouse=True)
def check_logging(caplog):
'''
Fixture validates that the python logger doesn't contain any warnings (or up) messages
If your test fails and it is ok to have such messages then you can clear the log at the end of your test
By callign: caplog.clear()
For example:
def test_foo(caplog):
logging.getLogger().warning('this is ok')
caplog.clear()
'''
yield
messages = [
"{}: {}".format(x.levelname, x.message) for x in caplog.get_records('call') if x.levelno >= logging.WARNING
]
if messages:
pytest.fail(
"warning messages encountered during testing: {}".format(messages)
)


@pytest.fixture(autouse=True)
def check_std_out_err(capfd):
'''
Fixture validates that there is no output to stdout or stderr.
If your test fails and it is ok to have output in stdout/stderr, you can disable the capture use "with capfd.disabled()"
For example:
def test_boo(capfd):
with capfd.disabled():
print("this is ok")
'''
yield
(out, err) = capfd.readouterr()
if out:
pytest.fail("Found output in stdout: [{}]".format(out.strip()))
if err:
pytest.fail("Found output in stderr: [{}]".format(err.strip()))

0 comments on commit 9dec920

Please sign in to comment.