cooperlees: Guess we could just set both environment variables ..
diff --git a/ptr.py b/ptr.py
index 7b24422..4bce8ed 100755
--- a/ptr.py
+++ b/ptr.py
@@ -702,7 +702,9 @@ async def _test_runner(
         else None
     )
     env = _set_build_env(extra_build_env_path)
-    env["COVERAGE_FILE"] = str(cov_data_path)
+    need_cov_env_var = await _using_coverage_5(venv_path)
+    if not need_cov_env_var:
+        env["COVERAGE_FILE"] = str(cov_data_path)
 
     while True:
         try:
@@ -743,6 +745,18 @@ async def _test_runner(
         queue.task_done()
 
 
+async def _using_coverage_5(venv_path: Path, timeout: float = 5) -> bool:
+    """ Check coverage version and set the correct environment var """
+    version_sub_str = "version 5."
+    if WINDOWS:
+        cov_exe = venv_path / "Scripts" / "coverage.exe"
+    else:
+        cov_exe = venv_path / "bin" / "coverage"
+
+    stdout, _stderr = await _gen_check_output((str(cov_exe), "--help"), timeout=timeout)
+    return version_sub_str in stdout.decode("utf-8")
+
+
 async def create_venv(
     mirror: str,
     py_exe: str = sys.executable,

Coverage >= 5.0 Breaks Coverage Analysis
## How is `ptr` not doing what you expect?

Analyzing coverage is failing on Mac OS X with coverage unable to find the `COVERAGE_FILE`
- May need to open an Issue / do a PR to coverage itself maybe here

## What is your suggestion to make this better?

Workout why the file can not be found. I think it will be something to do with the `COVERAGE_FILE` environment variable we set.
https://github.com/facebookincubator/ptr/blob/master/ptr.py#L705

## Code/Bug example?
Output: https://pastebin.com/2kdQQw8g

## How can a developer reproduce this?
Install coverage >= 5.0 and run ptr.
diff --git a/ptr_tests.py b/ptr_tests.py
index 77d5c59..702a057 100644
--- a/ptr_tests.py
+++ b/ptr_tests.py
@@ -455,6 +455,7 @@ class TestPtr(unittest.TestCase):
             self.assertTrue("[global]" in conf_file)
             self.assertTrue("/simple" in conf_file)
 
+    @patch("ptr._using_coverage_5", async_none)
     @patch("ptr._test_steps_runner", fake_test_steps_runner)
     def test_test_runner(self) -> None:
         queue = asyncio.Queue()  # type: asyncio.Queue
@@ -538,6 +539,14 @@ class TestPtr(unittest.TestCase):
             # Ensure we've "printed coverage"
             self.assertEqual(mock_print.call_count, 1)
 
+    @patch("ptr._gen_check_output", return_bytes_output)
+    def test_using_coverage_5(self) -> None:
+        self.assertFalse(
+            self.loop.run_until_complete(
+                ptr._using_coverage_5(Path("venvs/test"), timeout=1)
+            )
+        )
+
     def test_validate_base_dir(self) -> None:
         path_str = gettempdir()
         expected_path = Path(path_str)

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest pytest-cov pytest-xdist pytest-mock pytest-asyncio
3.7
requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
astroid==2.15.8
black==23.3.0
certifi @ file:///croot/certifi_1671487769961/work/certifi
click==8.1.8
coverage==7.2.7
dataclasses-json==0.6.7
dill==0.3.7
exceptiongroup==1.2.2
execnet==2.0.2
flake8==5.0.4
importlib-metadata==4.2.0
iniconfig==2.0.0
intervaltree==3.1.0
isort==5.11.5
lazy-object-proxy==1.9.0
libcst==1.0.1
marshmallow==3.19.0
mccabe==0.7.0
mypy==1.4.1
mypy-extensions==1.0.0
packaging==24.0
pathspec==0.11.2
platformdirs==4.0.0
pluggy==1.2.0
psutil==7.0.0
-e git+https://github.com/facebookincubator/ptr.git@8c8ee7ab353bd294a7de41eddd9a65ba7e28015c#egg=ptr
pycodestyle==2.9.1
pyflakes==2.5.0
Pygments==2.17.2
pylint==2.17.7
pyre-check==0.9.18
pyre-extensions==0.0.32
pytest==7.4.4
pytest-asyncio==0.21.2
pytest-cov==4.1.0
pytest-mock==3.11.1
pytest-xdist==3.5.0
PyYAML==6.0.1
sortedcontainers==2.4.0
tabulate==0.9.0
TestSlide==2.7.1
tomli==2.0.1
tomlkit==0.12.5
typed-ast==1.5.5
typeguard==2.13.3
typing-inspect==0.9.0
typing_extensions==4.7.1
wrapt==1.16.0
zipp==3.15.0

name: ptr
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2022.12.7=py37h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=22.3.1=py37h06a4308_0
  - python=3.7.16=h7a1cb2a_0
  - readline=8.2=h5eee18b_0
  - setuptools=65.6.3=py37h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.38.4=py37h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - astroid==2.15.8
      - black==23.3.0
      - click==8.1.8
      - coverage==7.2.7
      - dataclasses-json==0.6.7
      - dill==0.3.7
      - exceptiongroup==1.2.2
      - execnet==2.0.2
      - flake8==5.0.4
      - importlib-metadata==4.2.0
      - iniconfig==2.0.0
      - intervaltree==3.1.0
      - isort==5.11.5
      - lazy-object-proxy==1.9.0
      - libcst==1.0.1
      - marshmallow==3.19.0
      - mccabe==0.7.0
      - mypy==1.4.1
      - mypy-extensions==1.0.0
      - packaging==24.0
      - pathspec==0.11.2
      - platformdirs==4.0.0
      - pluggy==1.2.0
      - psutil==7.0.0
      - pycodestyle==2.9.1
      - pyflakes==2.5.0
      - pygments==2.17.2
      - pylint==2.17.7
      - pyre-check==0.9.18
      - pyre-extensions==0.0.32
      - pytest==7.4.4
      - pytest-asyncio==0.21.2
      - pytest-cov==4.1.0
      - pytest-mock==3.11.1
      - pytest-xdist==3.5.0
      - pyyaml==6.0.1
      - sortedcontainers==2.4.0
      - tabulate==0.9.0
      - testslide==2.7.1
      - tomli==2.0.1
      - tomlkit==0.12.5
      - typed-ast==1.5.5
      - typeguard==2.13.3
      - typing-extensions==4.7.1
      - typing-inspect==0.9.0
      - wrapt==1.16.0
      - zipp==3.15.0
prefix: /opt/conda/envs/ptr

ptr_tests.py::TestPtr::test_test_runner ptr_tests.py::TestPtr::test_using_coverage_5
ptr_tests.py::TestPtr::test_write_stats_file_raise
ptr_tests.py::TestPtr::test_analyze_coverage ptr_tests.py::TestPtr::test_analyze_coverage_errors ptr_tests.py::TestPtr::test_async_main ptr_tests.py::TestPtr::test_config ptr_tests.py::TestPtr::test_create_venv ptr_tests.py::TestPtr::test_create_venv_site_packages ptr_tests.py::TestPtr::test_find_setup_py ptr_tests.py::TestPtr::test_find_setup_py_exclude_default ptr_tests.py::TestPtr::test_gen_output ptr_tests.py::TestPtr::test_generate_black_command ptr_tests.py::TestPtr::test_generate_flake8_command ptr_tests.py::TestPtr::test_generate_install_cmd ptr_tests.py::TestPtr::test_generate_mypy_cmd ptr_tests.py::TestPtr::test_generate_pylint_command ptr_tests.py::TestPtr::test_generate_pyre_cmd ptr_tests.py::TestPtr::test_generate_test_suite_cmd ptr_tests.py::TestPtr::test_get_site_packages_path_error ptr_tests.py::TestPtr::test_get_test_modules ptr_tests.py::TestPtr::test_handle_debug ptr_tests.py::TestPtr::test_mac_osx_slash_private ptr_tests.py::TestPtr::test_main ptr_tests.py::TestPtr::test_parse_setup_cfg ptr_tests.py::TestPtr::test_print_non_configured_modules ptr_tests.py::TestPtr::test_print_test_results ptr_tests.py::TestPtr::test_process_reporter ptr_tests.py::TestPtr::test_set_build_env ptr_tests.py::TestPtr::test_set_pip_mirror ptr_tests.py::TestPtr::test_test_steps_runner ptr_tests.py::TestPtr::test_validate_base_dir ptr_tests.py::TestPtr::test_validate_base_dir_fail ptr_tests.py::TestPtr::test_write_stats_file
ptr.py
ptr.py