Skip to content

Commit

Permalink
Observe sys.argv, os.getpid(), import timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
Zac-HD committed Feb 3, 2024
1 parent 564506d commit 4911c23
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
3 changes: 2 additions & 1 deletion hypothesis-python/src/hypothesis/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
from hypothesis.internal.observability import (
OBSERVABILITY_COLLECT_COVERAGE,
TESTCASE_CALLBACKS,
_system_metadata,
deliver_json_blob,
make_testcase,
)
Expand Down Expand Up @@ -1066,7 +1067,6 @@ def _execute_once_for_engine(self, data: ConjectureData) -> None:
string_repr=self._string_repr,
arguments={**self._jsonable_arguments, **data._observability_args},
timing=self._timing_features,
metadata={},
coverage=tractable_coverage_report(trace) or None,
)
deliver_json_blob(tc)
Expand Down Expand Up @@ -1198,6 +1198,7 @@ def run_engine(self):
"metadata": {
"traceback": tb,
"predicates": ran_example._observability_predicates,
**_system_metadata(),
},
}
deliver_json_blob(tc)
Expand Down
17 changes: 15 additions & 2 deletions hypothesis-python/src/hypothesis/internal/observability.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
import json
import os
import sys
import time
import warnings
from datetime import date, timedelta
from functools import lru_cache
from typing import Callable, Dict, List, Optional

from hypothesis.configuration import storage_directory
Expand All @@ -38,7 +40,6 @@ def make_testcase(
string_repr: str = "<unknown>",
arguments: Optional[dict] = None,
timing: Dict[str, float],
metadata: Optional[dict] = None,
coverage: Optional[Dict[str, List[int]]] = None,
) -> dict:
if data.interesting_origin:
Expand Down Expand Up @@ -68,9 +69,9 @@ def make_testcase(
},
"timing": timing,
"metadata": {
**(metadata or {}),
"traceback": getattr(data.extra_information, "_expected_traceback", None),
"predicates": data._observability_predicates,
**_system_metadata(),
},
"coverage": coverage,
}
Expand All @@ -88,6 +89,18 @@ def _deliver_to_file(value): # pragma: no cover
f.write(json.dumps(value) + "\n")


_imported_at = time.time()


@lru_cache
def _system_metadata():
return {
"sys.argv": sys.argv,
"os.getpid()": os.getpid(),
"imported_at": _imported_at,
}


OBSERVABILITY_COLLECT_COVERAGE = (
"HYPOTHESIS_EXPERIMENTAL_OBSERVABILITY_NOCOVER" not in os.environ
)
Expand Down

0 comments on commit 4911c23

Please sign in to comment.