| 48 | |
| 49 | @pytest.fixture(scope="session") |
| 50 | def tmpdir_factory(request): |
| 51 | # type: (FixtureRequest) -> tmp.TempdirFactory |
| 52 | |
| 53 | # We use existing pytest configuration sources and values for tmpdir here to be drop-in |
| 54 | # ~compatible. |
| 55 | |
| 56 | basetemp = request.config.option.basetemp or os.path.join( |
| 57 | tempfile.gettempdir(), "pytest-of-{user}".format(user=getpass.getuser() or "unknown") |
| 58 | ) |
| 59 | |
| 60 | retention_count = int(request.config.getini("tmp_path_retention_count")) |
| 61 | if retention_count < 0: |
| 62 | raise ValueError( |
| 63 | "The `tmp_path_retention_count` value must be >= 0. Given: {count}.".format( |
| 64 | count=retention_count |
| 65 | ) |
| 66 | ) |
| 67 | |
| 68 | retention_policy = tmp.RetentionPolicy.for_value( |
| 69 | request.config.getini("tmp_path_retention_policy") |
| 70 | ) |
| 71 | |
| 72 | return tmp.tmpdir_factory( |
| 73 | basetemp=basetemp, retention_count=retention_count, retention_policy=retention_policy |
| 74 | ) |
| 75 | |
| 76 | |
| 77 | # This exposes the proper hooks for Python 2 or Python 3 as the case may be - the names on the LHS |