pytest-html-plus 0.4.2__tar.gz → 0.4.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: pytest-html-plus
3
- Version: 0.4.2
3
+ Version: 0.4.4
4
4
  Summary: Get started with rich pytest reports in under 3 seconds. Just install the plugin — no setup required. The simplest, fastest reporter for pytest.
5
5
  License: MIT
6
6
  Keywords: pytest,pytest-html-plus,pytest-plugin,html-test-report,beautiful-test-report,shareable-test-results,test-report,test-results,unit-test-report,functional-test-report,test-summary,reporting,python-testing,automated-testing,test-runner,report-generator,continuous-integration,ci-cd,github-actions,jenkins,pytest-html,pytest-report
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "pytest-html-plus"
3
- version = "0.4.2"
3
+ version = "0.4.4"
4
4
  description = "Get started with rich pytest reports in under 3 seconds. Just install the plugin — no setup required. The simplest, fastest reporter for pytest."
5
5
  readme = "README.md"
6
6
  authors = ["reporterplus"]
@@ -1,18 +1,20 @@
1
1
  import json
2
2
  from datetime import datetime
3
3
 
4
- from pytest_html_plus.utils import is_main_worker, get_env_marker, get_git_branch, get_git_commit, get_report_title, \
4
+ from pytest_html_plus.utils import is_main_worker, get_env_marker, get_report_title, \
5
5
  get_python_version
6
6
 
7
7
 
8
- def write_plus_metadata_if_main_worker(config, report_path, output_path="plus_metadata.json"):
8
+ def write_plus_metadata_if_main_worker(config, report_path, output_path="plus_metadata.json", **kwargs):
9
9
  if not is_main_worker():
10
10
  return
11
+ branch = kwargs.get("git_branch", "NA")
12
+ commit = kwargs.get("git_commit", "NA")
11
13
  metadata = {
12
14
  "report_title": get_report_title(output_path=report_path),
13
15
  "environment": get_env_marker(config),
14
- "branch": get_git_branch(),
15
- "commit": get_git_commit(),
16
+ "branch": branch,
17
+ "commit": commit,
16
18
  "python_version": get_python_version(),
17
19
  "generated_at": datetime.now().isoformat()
18
20
  }
@@ -162,11 +162,14 @@ def pytest_sessionfinish(session, exitstatus):
162
162
 
163
163
  def pytest_sessionstart(session):
164
164
  html_output = session.config.getoption("--html-output") or "report_output"
165
+ git_branch = session.config.getoption("--git-branch") or "NA"
166
+ git_commit = session.config.getoption("--git-commit") or "NA"
165
167
  configure_logging()
166
168
  session.config.addinivalue_line(
167
169
  "markers", "link(url): Add a link to external test case or documentation."
168
170
  )
169
- write_plus_metadata_if_main_worker(session.config, report_path=html_output)
171
+ write_plus_metadata_if_main_worker(session.config, report_path=html_output,
172
+ git_branch=git_branch, git_commit=git_commit)
170
173
 
171
174
 
172
175
  def pytest_load_initial_conftests(args):
@@ -221,6 +224,18 @@ def pytest_addoption(parser):
221
224
  default=None,
222
225
  help="Path to output the XML report (used with --generatexml)"
223
226
  )
227
+ parser.addoption(
228
+ "--git-branch",
229
+ action="store",
230
+ default="NA",
231
+ help="Helps show branch information on the report"
232
+ )
233
+ parser.addoption(
234
+ "--git-commit",
235
+ action="store",
236
+ default="NA",
237
+ help="Helps show commitId information on the report"
238
+ )
224
239
 
225
240
  import logging
226
241
  import sys
@@ -3,32 +3,6 @@ import subprocess
3
3
  import shutil
4
4
  import os
5
5
 
6
-
7
- def get_git_commit():
8
- try:
9
- return subprocess.check_output(["git", "rev-parse", "HEAD"]).decode().strip()
10
- except Exception:
11
- return "NA"
12
-
13
- def get_git_branch():
14
- branch_env_vars = [
15
- "GITHUB_HEAD_REF", "GITHUB_REF_NAME",
16
- "CI_COMMIT_REF_NAME", "BITBUCKET_BRANCH",
17
- "BUILD_SOURCEBRANCHNAME", "CIRCLE_BRANCH",
18
- "BRANCH_NAME", "TRAVIS_BRANCH"
19
- ]
20
- for var in branch_env_vars:
21
- val = os.getenv(var)
22
- if val:
23
- return val
24
-
25
- try:
26
- return subprocess.check_output(
27
- ["git", "rev-parse", "--abbrev-ref", "HEAD"]
28
- ).decode().strip()
29
- except Exception:
30
- return "NA"
31
-
32
6
  def get_env_marker(config):
33
7
  for arg in ("--env", "--environment"):
34
8
  if config.getoption(arg.lstrip("-").replace("-", "_"), default=None):