| 33 | |
| 34 | @pytest.fixture(scope="module") |
| 35 | def dir_server(): |
| 36 | with tmpdir() as d: |
| 37 | for fn in files: |
| 38 | with open(os.path.join(d, fn), "wb") as f: |
| 39 | f.write(b"a" * 10000) |
| 40 | |
| 41 | cmd = [sys.executable, "-m", "http.server", str(port)] |
| 42 | p = subprocess.Popen(cmd, cwd=d) |
| 43 | timeout = 10 |
| 44 | while True: |
| 45 | try: |
| 46 | requests.get(root) |
| 47 | break |
| 48 | except requests.exceptions.ConnectionError as e: |
| 49 | time.sleep(0.1) |
| 50 | timeout -= 0.1 |
| 51 | if timeout < 0: |
| 52 | raise RuntimeError("Server did not appear") from e |
| 53 | yield d |
| 54 | p.terminate() |
| 55 | try: |
| 56 | # reap the child, lest it keep the port bound for the next run |
| 57 | p.wait(timeout=3) |
| 58 | except subprocess.TimeoutExpired: |
| 59 | p.kill() |
| 60 | |
| 61 | |
| 62 | def test_simple(dir_server): |