forked from allure-framework/allure-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
attach log stdout stderr (via allure-framework#285)
- Loading branch information
1 parent
6791574
commit 8f98c1b
Showing
8 changed files
with
365 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
154 changes: 154 additions & 0 deletions
154
allure-pytest/test/capture_integration/test_attach_capture.py.off
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
import logging | ||
import pytest | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@pytest.fixture | ||
def fix1(): | ||
# Just for checking capture in fixtures | ||
print("fix setup") | ||
logger.info("fix setup") | ||
yield | ||
logger.info("fix teardown") | ||
print("fix teardown") | ||
|
||
|
||
### These tests really need to be parametrized, how to do it with doctest? ### | ||
|
||
|
||
def test_capture_stdout_logs_fd(fix1): | ||
""" | ||
>>> import os | ||
>>> allure_report = getfixture('allure_report_with_params')('--log-cli-level=INFO') | ||
|
||
>>> attachment_names = [] | ||
|
||
>>> test = None | ||
>>> for item in allure_report.test_cases: | ||
... if item["name"] == "test_capture_stdout_logs_fd": | ||
... test = item | ||
|
||
>>> for attachment in test["attachments"]: | ||
... name = attachment["name"] | ||
... source = os.path.join(allure_report.result_dir, attachment["source"]) | ||
... attachment_names.append(name) | ||
... if name == "stdout": | ||
... with open(source, "r") as f: | ||
... capstdout = f.read() | ||
... assert "fix setup" in capstdout | ||
... assert "begin test" in capstdout | ||
... assert "end test" in capstdout | ||
... assert "fix teardown" in capstdout | ||
... elif name == "log": | ||
... with open(source, "r") as f: | ||
... caplog = f.read() | ||
... assert "fix setup" in caplog | ||
... assert "something in test" in caplog | ||
... assert "fix teardown" in caplog | ||
|
||
>>> assert "stdout" in attachment_names | ||
>>> assert "stderr" in attachment_names | ||
>>> assert "log" in attachment_names | ||
""" | ||
print("begin test") | ||
logger.info("something in test") | ||
print("end test") | ||
|
||
|
||
def test_capture_stdout_no_logs(fix1): | ||
""" | ||
>>> import os | ||
>>> allure_report = getfixture('allure_report_with_params')('--log-cli-level=INFO', '-p no:logging') | ||
|
||
>>> attachment_names = [] | ||
|
||
>>> test = None | ||
>>> for item in allure_report.test_cases: | ||
... if item["name"] == "test_capture_stdout_no_logs": | ||
... test = item | ||
|
||
>>> for attachment in test["attachments"]: | ||
... name = attachment["name"] | ||
... source = os.path.join(allure_report.result_dir, attachment["source"]) | ||
... attachment_names.append(name) | ||
... if name == "stdout": | ||
... with open(source, "r") as f: | ||
... capstdout = f.read() | ||
... assert "fix setup" in capstdout | ||
... assert "begin test" in capstdout | ||
... assert "end test" in capstdout | ||
... assert "fix teardown" in capstdout | ||
... elif name == "log": | ||
... with open(source, "r") as f: | ||
... caplog = f.read() | ||
... assert caplog == "" | ||
|
||
>>> assert "stdout" in attachment_names | ||
>>> assert "stderr" in attachment_names | ||
>>> assert "log" in attachment_names | ||
""" | ||
print("begin test") | ||
logger.info("something in test") | ||
print("end test") | ||
|
||
|
||
def test_capture_stdout_logs_sys(fix1): | ||
""" | ||
>>> import os | ||
>>> allure_report = getfixture('allure_report_with_params')('--log-cli-level=INFO', '--capture=sys') | ||
|
||
>>> attachment_names = [] | ||
|
||
>>> test = None | ||
>>> for item in allure_report.test_cases: | ||
... if item["name"] == "test_capture_stdout_logs_sys": | ||
... test = item | ||
|
||
>>> with open("DOCTDEBUG", "w") as file: | ||
... a = file.write("{{{}}}\\n{{{}}}".format(test.keys(), test)) | ||
|
||
>>> for attachment in test["attachments"]: | ||
... name = attachment["name"] | ||
... source = os.path.join(allure_report.result_dir, attachment["source"]) | ||
... attachment_names.append(name) | ||
... if name == "stdout": | ||
... with open(source, "r") as f: | ||
... capstdout = f.read() | ||
... assert "fix setup" in capstdout | ||
... assert "begin test" in capstdout | ||
... assert "end test" in capstdout | ||
... assert "fix teardown" in capstdout | ||
... elif name == "log": | ||
... with open(source, "r") as f: | ||
... caplog = f.read() | ||
... assert "fix setup" in caplog | ||
... assert "something in test" in caplog | ||
... assert "fix teardown" in caplog | ||
|
||
>>> assert "stdout" in attachment_names | ||
>>> assert "stderr" in attachment_names | ||
>>> assert "log" in attachment_names | ||
""" | ||
print("begin test") | ||
logger.info("something in test") | ||
print("end test") | ||
|
||
|
||
def test_capture_disabled(fix1): | ||
""" | ||
>>> allure_report = getfixture('allure_report_with_params')('--log-cli-level=INFO', '--allure-no-capture') | ||
|
||
>>> attachment_names = [] | ||
|
||
>>> test = None | ||
>>> for item in allure_report.test_cases: | ||
... if item["name"] == "test_capture_disabled": | ||
... test = item | ||
|
||
>>> assert "attachments" not in test | ||
""" | ||
print("begin test") | ||
logger.info("something in test") | ||
print("end test") |
33 changes: 33 additions & 0 deletions
33
allure-pytest/test/capture_integration/test_attach_capture_disabled.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import logging | ||
import pytest | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@pytest.fixture | ||
def fix1(): | ||
# Just for checking capture in fixtures | ||
print("fix setup") | ||
logger.info("fix setup") | ||
yield | ||
logger.info("fix teardown") | ||
print("fix teardown") | ||
|
||
|
||
def test_capture_disabled(fix1): | ||
""" | ||
>>> allure_report = getfixture('allure_report_with_params')('--log-cli-level=INFO', '--allure-no-capture') | ||
>>> attachment_names = [] | ||
>>> test = None | ||
>>> for item in allure_report.test_cases: | ||
... if item["name"] == "test_capture_disabled": | ||
... test = item | ||
>>> assert "attachments" not in test | ||
""" | ||
print("begin test") | ||
logger.info("something in test") | ||
print("end test") |
55 changes: 55 additions & 0 deletions
55
allure-pytest/test/capture_integration/test_attach_capture_fd.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import logging | ||
import pytest | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@pytest.fixture | ||
def fix1(): | ||
# Just for checking capture in fixtures | ||
print("fix setup") | ||
logger.info("fix setup") | ||
yield | ||
logger.info("fix teardown") | ||
print("fix teardown") | ||
|
||
|
||
def test_capture_stdout_logs_fd(fix1): | ||
""" | ||
>>> import os | ||
>>> allure_report = getfixture('allure_report_with_params')('--log-cli-level=INFO') | ||
>>> attachment_names = [] | ||
>>> test = None | ||
>>> for item in allure_report.test_cases: | ||
... if item["name"] == "test_capture_stdout_logs_fd": | ||
... test = item | ||
>>> for attachment in test["attachments"]: | ||
... name = attachment["name"] | ||
... source = os.path.join(allure_report.result_dir, attachment["source"]) | ||
... attachment_names.append(name) | ||
... if name == "stdout": | ||
... with open(source, "r") as f: | ||
... capstdout = f.read() | ||
... assert "fix setup" in capstdout | ||
... assert "begin test" in capstdout | ||
... assert "end test" in capstdout | ||
... assert "fix teardown" in capstdout | ||
... elif name == "log": | ||
... with open(source, "r") as f: | ||
... caplog = f.read() | ||
... assert "fix setup" in caplog | ||
... assert "something in test" in caplog | ||
... assert "fix teardown" in caplog | ||
>>> assert "stdout" in attachment_names | ||
>>> assert "stderr" in attachment_names | ||
>>> assert "log" in attachment_names | ||
""" | ||
print("begin test") | ||
logger.info("something in test") | ||
print("end test") | ||
|
53 changes: 53 additions & 0 deletions
53
allure-pytest/test/capture_integration/test_attach_capture_no_logs.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import logging | ||
import pytest | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@pytest.fixture | ||
def fix1(): | ||
# Just for checking capture in fixtures | ||
print("fix setup") | ||
logger.info("fix setup") | ||
yield | ||
logger.info("fix teardown") | ||
print("fix teardown") | ||
|
||
|
||
def test_capture_stdout_no_logs(fix1): | ||
""" | ||
>>> import os | ||
>>> allure_report = getfixture('allure_report_with_params')('--log-cli-level=INFO', '-p no:logging') | ||
>>> attachment_names = [] | ||
>>> test = None | ||
>>> for item in allure_report.test_cases: | ||
... if item["name"] == "test_capture_stdout_no_logs": | ||
... test = item | ||
>>> for attachment in test["attachments"]: | ||
... name = attachment["name"] | ||
... source = os.path.join(allure_report.result_dir, attachment["source"]) | ||
... attachment_names.append(name) | ||
... if name == "stdout": | ||
... with open(source, "r") as f: | ||
... capstdout = f.read() | ||
... assert "fix setup" in capstdout | ||
... assert "begin test" in capstdout | ||
... assert "end test" in capstdout | ||
... assert "fix teardown" in capstdout | ||
... elif name == "log": | ||
... with open(source, "r") as f: | ||
... caplog = f.read() | ||
... assert caplog == "" | ||
>>> assert "stdout" in attachment_names | ||
>>> assert "stderr" in attachment_names | ||
>>> assert "log" in attachment_names | ||
""" | ||
print("begin test") | ||
logger.info("something in test") | ||
print("end test") | ||
|
57 changes: 57 additions & 0 deletions
57
allure-pytest/test/capture_integration/test_attach_capture_sys.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import logging | ||
import pytest | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@pytest.fixture | ||
def fix1(): | ||
# Just for checking capture in fixtures | ||
print("fix setup") | ||
logger.info("fix setup") | ||
yield | ||
logger.info("fix teardown") | ||
print("fix teardown") | ||
|
||
|
||
def test_capture_stdout_logs_sys(fix1): | ||
""" | ||
>>> import os | ||
>>> allure_report = getfixture('allure_report_with_params')('--log-cli-level=INFO', '--capture=sys') | ||
>>> attachment_names = [] | ||
>>> test = None | ||
>>> for item in allure_report.test_cases: | ||
... if item["name"] == "test_capture_stdout_logs_sys": | ||
... test = item | ||
>>> with open("DOCTDEBUG", "w") as file: | ||
... a = file.write("{{{}}}\\n{{{}}}".format(test.keys(), test)) | ||
>>> for attachment in test["attachments"]: | ||
... name = attachment["name"] | ||
... source = os.path.join(allure_report.result_dir, attachment["source"]) | ||
... attachment_names.append(name) | ||
... if name == "stdout": | ||
... with open(source, "r") as f: | ||
... capstdout = f.read() | ||
... assert "fix setup" in capstdout | ||
... assert "begin test" in capstdout | ||
... assert "end test" in capstdout | ||
... assert "fix teardown" in capstdout | ||
... elif name == "log": | ||
... with open(source, "r") as f: | ||
... caplog = f.read() | ||
... assert "fix setup" in caplog | ||
... assert "something in test" in caplog | ||
... assert "fix teardown" in caplog | ||
>>> assert "stdout" in attachment_names | ||
>>> assert "stderr" in attachment_names | ||
>>> assert "log" in attachment_names | ||
""" | ||
print("begin test") | ||
logger.info("something in test") | ||
print("end test") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters