From d8821826116ea467403a072838f0119f2471ab0a Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Thu, 2 Jul 2020 12:58:53 +0300 Subject: [PATCH 01/10] run tests for all branches --- .github/workflows/run-checks.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/run-checks.yml b/.github/workflows/run-checks.yml index 16a76bd..95126e6 100644 --- a/.github/workflows/run-checks.yml +++ b/.github/workflows/run-checks.yml @@ -2,9 +2,7 @@ name: Run checks on: push: - branches: [ master ] pull_request: - branches: [ master ] jobs: tox: From f9c87b74a63480a33ef68724b02eeab8b6f38cc9 Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Thu, 2 Jul 2020 13:32:12 +0300 Subject: [PATCH 02/10] extract individual report to own argument --md-verbose --- examples/conftest.py | 2 ++ examples/test_example.py | 42 ++++++++++++++++++++++++++++++++++++++++ src/pytest_md/plugin.py | 11 +++++++++-- tests/conftest.py | 4 ++-- 4 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 examples/conftest.py create mode 100644 examples/test_example.py diff --git a/examples/conftest.py b/examples/conftest.py new file mode 100644 index 0000000..6323bdc --- /dev/null +++ b/examples/conftest.py @@ -0,0 +1,2 @@ +""" example conftest """ +pytest_plugins = ("src.pytest_md.plugin",) # pylint: disable=invalid-name diff --git a/examples/test_example.py b/examples/test_example.py new file mode 100644 index 0000000..5f8660a --- /dev/null +++ b/examples/test_example.py @@ -0,0 +1,42 @@ +import random +import pytest + + +def test_failed(): + assert "emoji" == "hello world" + + +@pytest.mark.xfail +def test_xfailed(): + assert random.random() == 1.0 + + +@pytest.mark.xfail +def test_xpassed(): + assert 0.0 < random.random() < 1.0 + + +@pytest.mark.skip(reason="don't run this test") +def test_skipped(): + assert "pytest-emoji" != "" + + +@pytest.mark.parametrize( + "name, expected", + [ + ("Sara", "Hello Sara!"), + ("Mat", "Hello Mat!"), + ("Annie", "Hello Annie!"), + ], +) +def test_passed(name, expected): + assert f"Hello {name}!" == expected + + +@pytest.fixture +def number(): + return 1234 / 0 + + +def test_error(number): + assert number == number diff --git a/src/pytest_md/plugin.py b/src/pytest_md/plugin.py index 46d95dd..139203e 100644 --- a/src/pytest_md/plugin.py +++ b/src/pytest_md/plugin.py @@ -37,7 +37,7 @@ def _retrieve_emojis(self): def emoji(short, verbose): """Return the short or verbose emoji based on self.config.""" - if self.config.option.verbose > 0: + if self.config.option.md_verbose > 0: return verbose return short @@ -213,11 +213,12 @@ def pytest_sessionfinish(self, session) -> None: project_link = self.create_project_link() summary = self.create_summary() + self.report += f"{header}\n" self.report += f"{project_link}\n" self.report += f"{summary}\n" - if self.config.option.verbose > 0: + if self.config.option.md_verbose > 0: results = self.create_results() self.report += f"{results}" @@ -236,6 +237,12 @@ def pytest_addoption(parser): default=None, help="create markdown report file at given path.", ) + group.addoption( + "--md-verbose", + action="store_true", + dest="md_verbose", + help="individual test report", + ) def pytest_configure(config) -> None: diff --git a/tests/conftest.py b/tests/conftest.py index 16b9e41..0c128ae 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -116,9 +116,9 @@ def fixture_cli_options(mode): """Return CLI options for the different test scenarios.""" cli_options = { Mode.NORMAL: [], - Mode.VERBOSE: ["--verbose"], + Mode.VERBOSE: ["--md-verbose"], Mode.EMOJI_NORMAL: ["--emoji"], - Mode.EMOJI_VERBOSE: ["--verbose", "--emoji"], + Mode.EMOJI_VERBOSE: ["--md-verbose", "--emoji"], } return cli_options[mode] From 2b2b74e8a5775849be54e144f394f8150e1c3dcf Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Thu, 2 Jul 2020 17:04:53 +0300 Subject: [PATCH 03/10] implementing pytest-metadata support --- COMMUNITY.md | 2 ++ README.md | 44 ++++++++++++++++++++++++++++++++++- pytest.ini | 1 + src/pytest_md/plugin.py | 39 ++++++++++++++++++++++++++++--- tests/conftest.py | 43 +++++++++++++++++++++++++++++++--- tests/test_generate_report.py | 13 ++++++++++- tox.ini | 1 + 7 files changed, 135 insertions(+), 8 deletions(-) diff --git a/COMMUNITY.md b/COMMUNITY.md index 2f68e87..775a342 100644 --- a/COMMUNITY.md +++ b/COMMUNITY.md @@ -3,7 +3,9 @@ - [@hackebrot] - [@seanson] - [@ssd71] +- [@jupe] [@seanson]: https://github.com/seanson [@hackebrot]: https://github.com/hackebrot [@ssd71]: https://github.com/ssd71 +[@jupe]: https://github.com/jupe diff --git a/README.md b/README.md index 88ac354..2912b98 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ $ pytest --md report.md emojis in the generated Markdown test report: ```text -$ pytest --emoji -v --md report.md +$ pytest --emoji --md-verbose --md report.md ``` ```Markdown @@ -119,7 +119,49 @@ $ pytest --emoji -v --md report.md - 1 error 😡 ``` +## pytest-metadata + +**pytest-md** also integrates with [pytest-metadata], which allows us to include +metadata in the generated Markdown test report: + +```text +$ pytest --md-metadata --metadata key=value +``` + +````markdown +# Test Report + +*Report generated on 02-Jul-2020 at 14:11:48 by [pytest-md]* + +[pytest-md]: https://github.com/hackebrot/pytest-md + +## Summary + +8 tests ran in 0.08 seconds + +- 1 error +- 1 failed +- 3 passed +- 1 skipped +- 1 xfailed +- 1 xpassed + +## Metadata + +Python: 3.7.7 +Platform: Darwin-19.5.0-x86_64-i386-64bit +Packages + pytest: 5.4.3 + py: 1.9.0 + pluggy: 0.13.1 +key: value +Plugins + metadata: 1.10.0 + +```` + [pytest-emoji]: https://github.com/hackebrot/pytest-emoji +[pytest-metadata]: https://github.com/pytest-dev/pytest-metadata ## Credits diff --git a/pytest.ini b/pytest.ini index 29d34ba..c76fb50 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,3 +1,4 @@ [pytest] markers = emoji: tests which are skipped if pytest-emoji is not installed. + metadata: tests which are skipped if pytest-metadata is not installed. diff --git a/src/pytest_md/plugin.py b/src/pytest_md/plugin.py index 139203e..0a81765 100644 --- a/src/pytest_md/plugin.py +++ b/src/pytest_md/plugin.py @@ -20,11 +20,14 @@ class Outcome(enum.Enum): class MarkdownPlugin: """Plugin for generating Markdown reports.""" - def __init__(self, config, report_path, emojis_enabled: bool = False) -> None: + def __init__(self, config, report_path, + emojis_enabled: bool = False, + metadata_installed: bool = False) -> None: self.config = config self.report_path = report_path self.report = "" self.emojis_enabled = emojis_enabled + self.metadata_installed = metadata_installed self.reports: Dict[Outcome, List] = collections.defaultdict(list) @@ -151,6 +154,25 @@ def create_summary(self) -> str: return summary + "\n\n" + outcome_text + def create_metadata(self) -> str: + """ Create environment section for the Markdown report.""" + outcome_text = "" + + def _generate_md(items, indentation=0): + nonlocal outcome_text + for key, value in items: + if isinstance(value, dict): + outcome_text += f'{" "*indentation}{key}\n' + _generate_md(value.items(), indentation+2) + else: + outcome_text += f'{" "*indentation}{key}: {value}\n' + + _generate_md(self.config._metadata.items()) + + summary = "## Metadata" + + return summary + "\n\n" + outcome_text + def create_results(self) -> str: """Create results for the individual tests for the Markdown report.""" @@ -213,12 +235,16 @@ def pytest_sessionfinish(self, session) -> None: project_link = self.create_project_link() summary = self.create_summary() - self.report += f"{header}\n" self.report += f"{project_link}\n" self.report += f"{summary}\n" - if self.config.option.md_verbose > 0: + if self.config.option.md_metadata: + assert self.metadata_installed, 'pytest-metadata is not installed' + metadata = self.create_metadata() + self.report += f"{metadata}" + + if self.config.option.md_verbose: results = self.create_results() self.report += f"{results}" @@ -237,6 +263,12 @@ def pytest_addoption(parser): default=None, help="create markdown report file at given path.", ) + group.addoption( + "--md-metadata", + action="store_true", + dest="md_metadata", + help="Add environment section to report", + ) group.addoption( "--md-verbose", action="store_true", @@ -265,6 +297,7 @@ def emojis_enabled() -> bool: config, report_path=pathlib.Path(mdpath).expanduser().resolve(), emojis_enabled=emojis_enabled(), + metadata_installed=config.pluginmanager.hasplugin('metadata') ) config.pluginmanager.register(config._md, "md_plugin") diff --git a/tests/conftest.py b/tests/conftest.py index 0c128ae..ca946e6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,6 +1,7 @@ import enum import datetime import textwrap +import re import freezegun import pytest @@ -107,6 +108,7 @@ class Mode(enum.Enum): NORMAL = "normal" VERBOSE = "verbose" + METADATA = 'metadata' EMOJI_NORMAL = "emoji_normal" EMOJI_VERBOSE = "emoji_verbose" @@ -117,6 +119,7 @@ def fixture_cli_options(mode): cli_options = { Mode.NORMAL: [], Mode.VERBOSE: ["--md-verbose"], + Mode.METADATA: ["--md-metadata", "--metadata", "key", "value"], Mode.EMOJI_NORMAL: ["--emoji"], Mode.EMOJI_VERBOSE: ["--md-verbose", "--emoji"], } @@ -242,6 +245,34 @@ def test_failed(): """ ) + if mode is Mode.METADATA: + + return re.compile(textwrap.dedent( + f"""\ + \\# Test Report + + \\*Report generated on {report_date} at {report_time} by \\[pytest-md\\]\\* + + \\[pytest-md\\]\\: https://github\\.com/hackebrot/pytest-md + + \\#\\# Summary + + 8 tests ran in 0.00 seconds + + - 1 error + - 1 failed + - 3 passed + - 1 skipped + - 1 xfailed + - 1 xpassed + + \\#\\# Metadata + + [\w\W]+ + key\\: value + [\w\W]+ + """)) + # Return the default report for Mode.NORMAL and Mode.VERBOSE if mode is Mode.VERBOSE: return textwrap.dedent( @@ -371,6 +402,8 @@ def pytest_generate_tests(metafunc): [ Mode.NORMAL, Mode.VERBOSE, + Mode.METADATA, + pytest.param(Mode.METADATA, marks=pytest.mark.metadata), pytest.param(Mode.EMOJI_NORMAL, marks=pytest.mark.emoji), pytest.param(Mode.EMOJI_VERBOSE, marks=pytest.mark.emoji), ], @@ -378,10 +411,14 @@ def pytest_generate_tests(metafunc): def pytest_collection_modifyitems(items, config): - """Skip tests marked with "emoji" if pytest-emoji is not installed.""" - if config.pluginmanager.hasplugin("emoji"): + """Skip tests marked with "emoji" if pytest-emoji and pytest-metadata is not installed.""" + has_emoji = config.pluginmanager.hasplugin("emoji") + has_metadata = config.pluginmanager.hasplugin("metadata") + if has_emoji and has_metadata: return for item in items: - if item.get_closest_marker("emoji"): + if item.get_closest_marker("emoji") and not has_emoji: item.add_marker(pytest.mark.skip(reason="pytest-emoji is not installed")) + if item.get_closest_marker("metadata") and not has_metadata: + item.add_marker(pytest.mark.skip(reason="pytest-metadata is not installed")) diff --git a/tests/test_generate_report.py b/tests/test_generate_report.py index e797061..2b95bff 100644 --- a/tests/test_generate_report.py +++ b/tests/test_generate_report.py @@ -1,3 +1,6 @@ +from typing import Pattern + + def test_generate_report(testdir, cli_options, report_path, report_content): """Check the contents of a generated Markdown report.""" # run pytest with the following CLI options @@ -7,5 +10,13 @@ def test_generate_report(testdir, cli_options, report_path, report_content): # as we have at least one failure assert result.ret == 1 + report = report_path.read_text() + # Check the generated Markdown report - assert report_path.read_text() == report_content + if isinstance(report_content, Pattern): + with open('/Users/jussiva/git/github/opentmi/pytest-md/content.log', "w") as file: + file.writelines(report) + file.writelines(report_content.pattern) + assert report_content.match(report) + else: + assert report == report_content diff --git a/tox.ini b/tox.ini index 187d873..6ec8326 100644 --- a/tox.ini +++ b/tox.ini @@ -6,6 +6,7 @@ deps = freezegun pytest>=5.4.0 emoji: pytest-emoji + metadata: pytest-metadata commands = pytest -v {posargs:tests} [testenv:flake8] From 0876e25f58f6aa1a50d8d5bb3656828d7d91a32b Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Fri, 3 Jul 2020 10:29:23 +0300 Subject: [PATCH 04/10] fix tests --- .github/workflows/run-checks.yml | 6 +++++- tests/conftest.py | 3 +-- tox.ini | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/run-checks.yml b/.github/workflows/run-checks.yml index 95126e6..290921d 100644 --- a/.github/workflows/run-checks.yml +++ b/.github/workflows/run-checks.yml @@ -10,12 +10,16 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - environment: ["py36", "py37", "py36-emoji", "py37-emoji", "mypy", "flake8"] + environment: ["py36", "py37", "py36-metadata", "py37-metadata", "py36-emoji", "py37-emoji", "mypy", "flake8"] include: - environment: "py36" python: "3.6" - environment: "py37" python: "3.7" + - environment: "py36-metadata" + python: "3.6" + - environment: "py37-metadata" + python: "3.7" - environment: "py36-emoji" python: "3.6" - environment: "py37-emoji" diff --git a/tests/conftest.py b/tests/conftest.py index ca946e6..e3630f1 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -380,7 +380,7 @@ def test_failed(): @pytest.fixture(name="report_path") def fixture_report_path(tmp_path): """Return a temporary path for writing the Markdown report.""" - return tmp_path / "emoji_report.md" + return tmp_path / "report.md" def pytest_make_parametrize_id(config, val): @@ -402,7 +402,6 @@ def pytest_generate_tests(metafunc): [ Mode.NORMAL, Mode.VERBOSE, - Mode.METADATA, pytest.param(Mode.METADATA, marks=pytest.mark.metadata), pytest.param(Mode.EMOJI_NORMAL, marks=pytest.mark.emoji), pytest.param(Mode.EMOJI_VERBOSE, marks=pytest.mark.emoji), diff --git a/tox.ini b/tox.ini index 6ec8326..a96f71d 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py36,py37,{py36,py37}-emoji,mypy,flake8 +envlist = py36,py37,{py36,py37}-emoji,{py36,py37}-metadata,mypy,flake8 [testenv] deps = From 8fb69f5233d0577e7715325102a3f0336a9a576e Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Fri, 3 Jul 2020 10:39:24 +0300 Subject: [PATCH 05/10] cleanup --- tests/conftest.py | 16 ++++++++-------- tests/test_generate_report.py | 3 --- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index e3630f1..b72405d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -250,27 +250,27 @@ def test_failed(): return re.compile(textwrap.dedent( f"""\ \\# Test Report - + \\*Report generated on {report_date} at {report_time} by \\[pytest-md\\]\\* \\[pytest-md\\]\\: https://github\\.com/hackebrot/pytest-md - + \\#\\# Summary - + 8 tests ran in 0.00 seconds - + - 1 error - 1 failed - 3 passed - 1 skipped - 1 xfailed - 1 xpassed - + \\#\\# Metadata - - [\w\W]+ + + [\\w\\W]+ key\\: value - [\w\W]+ + [\\w\\W]+ """)) # Return the default report for Mode.NORMAL and Mode.VERBOSE diff --git a/tests/test_generate_report.py b/tests/test_generate_report.py index 2b95bff..d5cba20 100644 --- a/tests/test_generate_report.py +++ b/tests/test_generate_report.py @@ -14,9 +14,6 @@ def test_generate_report(testdir, cli_options, report_path, report_content): # Check the generated Markdown report if isinstance(report_content, Pattern): - with open('/Users/jussiva/git/github/opentmi/pytest-md/content.log', "w") as file: - file.writelines(report) - file.writelines(report_content.pattern) assert report_content.match(report) else: assert report == report_content From 68b1f3912760aab28c5f52b6de5c5bf7b4a04642 Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Fri, 3 Jul 2020 11:00:54 +0300 Subject: [PATCH 06/10] fix one more lint error --- tests/conftest.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index b72405d..0a88c9e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -410,7 +410,10 @@ def pytest_generate_tests(metafunc): def pytest_collection_modifyitems(items, config): - """Skip tests marked with "emoji" if pytest-emoji and pytest-metadata is not installed.""" + """ + Skip tests marked with "emoji" if pytest-emoji and + pytest-metadata is not installed. + """ has_emoji = config.pluginmanager.hasplugin("emoji") has_metadata = config.pluginmanager.hasplugin("metadata") if has_emoji and has_metadata: From 2ca98c48e5ddd1dd4afb336e3c0c0b46d9f3e199 Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Mon, 6 Jul 2020 15:09:16 +0300 Subject: [PATCH 07/10] small metadata reporting styling tuning use list style to make md more readable --- src/pytest_md/plugin.py | 4 ++-- tests/conftest.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pytest_md/plugin.py b/src/pytest_md/plugin.py index 0a81765..bab4e56 100644 --- a/src/pytest_md/plugin.py +++ b/src/pytest_md/plugin.py @@ -162,10 +162,10 @@ def _generate_md(items, indentation=0): nonlocal outcome_text for key, value in items: if isinstance(value, dict): - outcome_text += f'{" "*indentation}{key}\n' + outcome_text += f'{" "*indentation}- {key}\n' _generate_md(value.items(), indentation+2) else: - outcome_text += f'{" "*indentation}{key}: {value}\n' + outcome_text += f'{" "*indentation}- {key}: {value}\n' _generate_md(self.config._metadata.items()) diff --git a/tests/conftest.py b/tests/conftest.py index 0a88c9e..c35d01e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -269,7 +269,7 @@ def test_failed(): \\#\\# Metadata [\\w\\W]+ - key\\: value + - key\\: value [\\w\\W]+ """)) From 04754d4e3a86201e9423648c9eddacc327763b0d Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Thu, 16 Jul 2020 10:51:39 +0300 Subject: [PATCH 08/10] first round of review feedback based changes --- examples/conftest.py | 2 -- examples/test_example.py | 42 ---------------------------------------- src/pytest_md/plugin.py | 21 +++++++++++--------- tests/conftest.py | 2 +- tox.ini | 2 +- 5 files changed, 14 insertions(+), 55 deletions(-) delete mode 100644 examples/conftest.py delete mode 100644 examples/test_example.py diff --git a/examples/conftest.py b/examples/conftest.py deleted file mode 100644 index 6323bdc..0000000 --- a/examples/conftest.py +++ /dev/null @@ -1,2 +0,0 @@ -""" example conftest """ -pytest_plugins = ("src.pytest_md.plugin",) # pylint: disable=invalid-name diff --git a/examples/test_example.py b/examples/test_example.py deleted file mode 100644 index 5f8660a..0000000 --- a/examples/test_example.py +++ /dev/null @@ -1,42 +0,0 @@ -import random -import pytest - - -def test_failed(): - assert "emoji" == "hello world" - - -@pytest.mark.xfail -def test_xfailed(): - assert random.random() == 1.0 - - -@pytest.mark.xfail -def test_xpassed(): - assert 0.0 < random.random() < 1.0 - - -@pytest.mark.skip(reason="don't run this test") -def test_skipped(): - assert "pytest-emoji" != "" - - -@pytest.mark.parametrize( - "name, expected", - [ - ("Sara", "Hello Sara!"), - ("Mat", "Hello Mat!"), - ("Annie", "Hello Annie!"), - ], -) -def test_passed(name, expected): - assert f"Hello {name}!" == expected - - -@pytest.fixture -def number(): - return 1234 / 0 - - -def test_error(number): - assert number == number diff --git a/src/pytest_md/plugin.py b/src/pytest_md/plugin.py index bab4e56..7803f87 100644 --- a/src/pytest_md/plugin.py +++ b/src/pytest_md/plugin.py @@ -22,12 +22,12 @@ class MarkdownPlugin: def __init__(self, config, report_path, emojis_enabled: bool = False, - metadata_installed: bool = False) -> None: + metadata_enabled: bool = False) -> None: self.config = config self.report_path = report_path self.report = "" self.emojis_enabled = emojis_enabled - self.metadata_installed = metadata_installed + self.metadata_enabled = metadata_enabled self.reports: Dict[Outcome, List] = collections.defaultdict(list) @@ -162,10 +162,10 @@ def _generate_md(items, indentation=0): nonlocal outcome_text for key, value in items: if isinstance(value, dict): - outcome_text += f'{" "*indentation}- {key}\n' + outcome_text += f'{" "*indentation}* {key}\n' _generate_md(value.items(), indentation+2) else: - outcome_text += f'{" "*indentation}- {key}: {value}\n' + outcome_text += f'{" "*indentation}* {key}: {value}\n' _generate_md(self.config._metadata.items()) @@ -239,10 +239,9 @@ def pytest_sessionfinish(self, session) -> None: self.report += f"{project_link}\n" self.report += f"{summary}\n" - if self.config.option.md_metadata: - assert self.metadata_installed, 'pytest-metadata is not installed' - metadata = self.create_metadata() - self.report += f"{metadata}" + if self.metadata_enabled and self.config.option.md_metadata: + metadata = self.create_metadata() + self.report += f"{metadata}" if self.config.option.md_verbose: results = self.create_results() @@ -293,11 +292,15 @@ def emojis_enabled() -> bool: return config.option.emoji is True + def metadata_enabled() -> bool: + """ Check if pytest-metadata is installed """ + return config.pluginmanager.hasplugin('metadata') + config._md = MarkdownPlugin( config, report_path=pathlib.Path(mdpath).expanduser().resolve(), emojis_enabled=emojis_enabled(), - metadata_installed=config.pluginmanager.hasplugin('metadata') + metadata_enabled=metadata_enabled() ) config.pluginmanager.register(config._md, "md_plugin") diff --git a/tests/conftest.py b/tests/conftest.py index c35d01e..c884f98 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -269,7 +269,7 @@ def test_failed(): \\#\\# Metadata [\\w\\W]+ - - key\\: value + * key\\: value [\\w\\W]+ """)) diff --git a/tox.ini b/tox.ini index a96f71d..4458d44 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py36,py37,{py36,py37}-emoji,{py36,py37}-metadata,mypy,flake8 +envlist = py36, py37, {py36, py37}-{emoji, metadata, emoji-metadata}, mypy, flake8 [testenv] deps = From d0718e99a39eff3c99c8ba35e8087064cf617655 Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Thu, 16 Jul 2020 11:18:53 +0300 Subject: [PATCH 09/10] simplify metadata_enabled and add test with emoji+metadata --- .github/workflows/run-checks.yml | 12 ++++++++++-- src/pytest_md/plugin.py | 8 +++++--- tests/conftest.py | 33 +++++++++++++++++++++++++++++++- 3 files changed, 47 insertions(+), 6 deletions(-) diff --git a/.github/workflows/run-checks.yml b/.github/workflows/run-checks.yml index 290921d..889aa79 100644 --- a/.github/workflows/run-checks.yml +++ b/.github/workflows/run-checks.yml @@ -10,7 +10,11 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - environment: ["py36", "py37", "py36-metadata", "py37-metadata", "py36-emoji", "py37-emoji", "mypy", "flake8"] + environment: ["py36", "py37", + "py36-metadata", "py37-metadata", + "py36-emoji", "py37-emoji", + "py36-emoji-metadata", "py37-emoji-metadata" + "mypy", "flake8"] include: - environment: "py36" python: "3.6" @@ -24,12 +28,16 @@ jobs: python: "3.6" - environment: "py37-emoji" python: "3.7" + - environment: "py36-emoji-metadata" + python: "3.6" + - environment: "py37-emoji-metadata" + python: "3.7" - environment: "mypy" python: "3.7" - environment: "flake8" python: "3.7" - container: + container: image: python:${{ matrix.python }} steps: diff --git a/src/pytest_md/plugin.py b/src/pytest_md/plugin.py index 7803f87..a17a052 100644 --- a/src/pytest_md/plugin.py +++ b/src/pytest_md/plugin.py @@ -239,7 +239,7 @@ def pytest_sessionfinish(self, session) -> None: self.report += f"{project_link}\n" self.report += f"{summary}\n" - if self.metadata_enabled and self.config.option.md_metadata: + if self.metadata_enabled: metadata = self.create_metadata() self.report += f"{metadata}" @@ -293,8 +293,10 @@ def emojis_enabled() -> bool: return config.option.emoji is True def metadata_enabled() -> bool: - """ Check if pytest-metadata is installed """ - return config.pluginmanager.hasplugin('metadata') + """ Check if pytest-metadata is installed and enabled """ + if not config.pluginmanager.hasplugin('metadata'): + return False + return config.option.md_metadata config._md = MarkdownPlugin( config, diff --git a/tests/conftest.py b/tests/conftest.py index c884f98..89be22b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -108,7 +108,8 @@ class Mode(enum.Enum): NORMAL = "normal" VERBOSE = "verbose" - METADATA = 'metadata' + METADATA = "metadata" + EMOJI_METADATA = "emoji_metadata" EMOJI_NORMAL = "emoji_normal" EMOJI_VERBOSE = "emoji_verbose" @@ -120,6 +121,7 @@ def fixture_cli_options(mode): Mode.NORMAL: [], Mode.VERBOSE: ["--md-verbose"], Mode.METADATA: ["--md-metadata", "--metadata", "key", "value"], + Mode.EMOJI_METADATA: ["--emoji", "--md-metadata", "--metadata", "key", "value"], Mode.EMOJI_NORMAL: ["--emoji"], Mode.EMOJI_VERBOSE: ["--md-verbose", "--emoji"], } @@ -273,6 +275,34 @@ def test_failed(): [\\w\\W]+ """)) + if mode is Mode.EMOJI_METADATA: + + return re.compile(textwrap.dedent( + f"""\ + \\# Test Report + + \\*Report generated on {report_date} at {report_time} by \\[pytest-md\\]\\* \\📝 + + \\[pytest-md\\]\\: https://github\\.com/hackebrot/pytest-md + + \\#\\# Summary + + 8 tests ran in 0.00 seconds \\⏱ + + - 1 \\💩 + - 1 \\😿 + - 3 \\🦊 + - 1 \\🙈 + - 1 \\🤓 + - 1 \\😜 + + \\#\\# Metadata + + [\\w\\W]+ + * key\\: value + [\\w\\W]+ + """)) + # Return the default report for Mode.NORMAL and Mode.VERBOSE if mode is Mode.VERBOSE: return textwrap.dedent( @@ -405,6 +435,7 @@ def pytest_generate_tests(metafunc): pytest.param(Mode.METADATA, marks=pytest.mark.metadata), pytest.param(Mode.EMOJI_NORMAL, marks=pytest.mark.emoji), pytest.param(Mode.EMOJI_VERBOSE, marks=pytest.mark.emoji), + pytest.param(Mode.EMOJI_METADATA, marks=[pytest.mark.emoji,pytest.mark.metadata]), ], ) From a1cff60d393440ff36c08458a044c9b3d2a1bb8c Mon Sep 17 00:00:00 2001 From: Jussi Vatjus-Anttila Date: Thu, 16 Jul 2020 11:20:47 +0300 Subject: [PATCH 10/10] pylint cleanup --- src/pytest_md/plugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pytest_md/plugin.py b/src/pytest_md/plugin.py index a17a052..8af7a1e 100644 --- a/src/pytest_md/plugin.py +++ b/src/pytest_md/plugin.py @@ -240,8 +240,8 @@ def pytest_sessionfinish(self, session) -> None: self.report += f"{summary}\n" if self.metadata_enabled: - metadata = self.create_metadata() - self.report += f"{metadata}" + metadata = self.create_metadata() + self.report += f"{metadata}" if self.config.option.md_verbose: results = self.create_results()