-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0d66f02
commit 8056e86
Showing
6 changed files
with
90 additions
and
0 deletions.
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
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 |
---|---|---|
|
@@ -8,3 +8,6 @@ twine | |
flake8 | ||
mypy | ||
coverage | ||
|
||
# Test | ||
pytest |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import coredumpy | ||
|
||
|
||
def pytest_addoption(parser): | ||
parser.addoption( | ||
"--enable-coredumpy", | ||
action="store_true", | ||
help="Enable coredumpy plugin.", | ||
) | ||
|
||
parser.addoption( | ||
"--coredumpy-dir", | ||
action="store", | ||
default="./coredumpy", | ||
help="The directory to store the core dump files.", | ||
) | ||
|
||
|
||
def pytest_exception_interact(node, call, report): | ||
if not node.config.getoption("--enable-coredumpy"): | ||
return | ||
|
||
import pytest | ||
if isinstance(report, pytest.TestReport): | ||
try: | ||
tb = call.excinfo.tb | ||
while tb.tb_next: | ||
tb = tb.tb_next | ||
coredumpy.dump(tb.tb_frame, directory=node.config.getoption("--coredumpy-dir")) | ||
except Exception: | ||
pass |
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,43 @@ | ||
# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0 | ||
# For details: https://github.com/gaogaotiantian/coredumpy/blob/master/NOTICE.txt | ||
|
||
|
||
import os | ||
import tempfile | ||
import textwrap | ||
|
||
from .base import TestBase | ||
|
||
|
||
class TestPytest(TestBase): | ||
def test_pytest(self): | ||
with tempfile.TemporaryDirectory() as tmpdir: | ||
test = textwrap.dedent(f""" | ||
import pytest | ||
import os | ||
def test_for_pytest_equal(): | ||
assert 1 == 2 | ||
def test_for_pytest_greater(): | ||
assert 1 > 2 | ||
""") | ||
with open(os.path.join(tmpdir, "test.py"), "w") as f: | ||
f.write(test) | ||
|
||
test_path = os.path.join(tmpdir, "test.py") | ||
dump_path = os.path.join(tmpdir, "dump") | ||
|
||
script = f""" | ||
import pytest | ||
pytest.main(["--enable-coredumpy", "--coredumpy-dir", {repr(dump_path)}, {repr(test_path)}]) | ||
""" | ||
self.run_script(script) | ||
self.assertEqual(len(os.listdir(dump_path)), 2) | ||
|
||
# Without the enable, it should not produce dumps | ||
script = f""" | ||
import pytest | ||
pytest.main(["--coredumpy-dir", {repr(dump_path)}, {repr(test_path)}]) | ||
""" | ||
self.run_script(script) | ||
self.assertEqual(len(os.listdir(dump_path)), 2) |