| 31 | |
| 32 | @pytest.fixture(scope="module") |
| 33 | def dir_server(): |
| 34 | with tmpdir() as d: |
| 35 | for fn in files: |
| 36 | with open(os.path.join(d, fn), "wb") as f: |
| 37 | f.write(b"a" * 10000) |
| 38 | |
| 39 | cmd = [sys.executable, "-m", "http.server", "8999"] |
| 40 | p = subprocess.Popen(cmd, cwd=d) |
| 41 | timeout = 10 |
| 42 | while True: |
| 43 | try: |
| 44 | requests.get("http://localhost:8999") |
| 45 | break |
| 46 | except requests.exceptions.ConnectionError as e: |
| 47 | time.sleep(0.1) |
| 48 | timeout -= 0.1 |
| 49 | if timeout < 0: |
| 50 | raise RuntimeError("Server did not appear") from e |
| 51 | yield d |
| 52 | p.terminate() |
| 53 | |
| 54 | |
| 55 | def test_simple(dir_server): |