|
| 1 | +import os |
| 2 | + |
1 | 3 | from pathlib import Path |
2 | 4 | from platform import system |
| 5 | +from tempfile import mkstemp |
| 6 | +from textwrap import dedent |
3 | 7 |
|
4 | 8 | from invoke import run, task |
5 | 9 |
|
6 | 10 |
|
7 | 11 | CURDIR = Path.cwd() |
8 | 12 | SRCPATH = CURDIR / 'src' |
9 | 13 | UNIT_TESTS = CURDIR / 'tests' |
| 14 | +DUMMYHANDLERS = UNIT_TESTS / 'resources' / 'my_dummy_handlers' |
10 | 15 |
|
11 | 16 | # If you want colored output for the tasks, use `run()` with `pty=True` |
12 | 17 | # Not on Windows, though -- it'll fail if you have `pty=True` |
@@ -48,18 +53,36 @@ def coverage(context): |
48 | 53 | pty=(not system() == 'Windows')) |
49 | 54 | run('coverage html') |
50 | 55 |
|
| 56 | +def _setup_atest(): |
| 57 | + _, tempconf = mkstemp() |
| 58 | + with open(tempconf, 'w') as f: |
| 59 | + f.write('''dummy_handler_metadata: |
| 60 | + handler: MyDummyMetadataHandler |
| 61 | + keyword: run_metadata_dummy_handler |
| 62 | + tags: oxygen-metadata''') |
| 63 | + return (tempconf, |
| 64 | + os.pathsep.join([str(SRCPATH), |
| 65 | + str(DUMMYHANDLERS)])) |
| 66 | + |
51 | 67 | @task(help={ |
52 | 68 | 'rf': 'Additional command-line arguments for Robot Framework as ' |
53 | 69 | 'single string. E.g: invoke atest --rf "--name my_suite"' |
54 | 70 | }) |
55 | 71 | def atest(context, rf=''): |
56 | | - run(f'robot ' |
57 | | - f'--pythonpath {str(SRCPATH)} ' |
58 | | - f'--dotted ' |
59 | | - f'{rf} ' |
60 | | - f'--listener oxygen.listener ' |
61 | | - f'{str(CURDIR / "tests" / "atest")}', |
62 | | - pty=(not system() == 'Windows')) |
| 72 | + tempconf, pythonpath = _setup_atest() |
| 73 | + run(f'python -m oxygen --add-config {tempconf}', |
| 74 | + env={'PYTHONPATH': pythonpath}) |
| 75 | + try: |
| 76 | + run(f'robot ' |
| 77 | + f'--pythonpath {str(SRCPATH)} ' |
| 78 | + f'--pythonpath {str(DUMMYHANDLERS)} ' |
| 79 | + f'--dotted ' |
| 80 | + f'{rf} ' |
| 81 | + f'--listener oxygen.listener ' |
| 82 | + f'{str(CURDIR / "tests" / "atest")}', |
| 83 | + pty=(not system() == 'Windows')) |
| 84 | + finally: |
| 85 | + run('python -m oxygen --reset-config', env={'PYTHONPATH': pythonpath}) |
63 | 86 |
|
64 | 87 | @task |
65 | 88 | def test(context): |
|
0 commit comments