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