| 1 |
import os |
| 2 |
import pexpect |
| 3 |
import pytest |
| 4 |
|
| 5 |
@pytest.fixture |
| 6 |
def short_env(tmpdir): |
| 7 |
p = tmpdir.join("config.yaml") |
| 8 |
p.write( |
| 9 |
""" |
| 10 |
targets: |
| 11 |
test1: |
| 12 |
drivers: {} |
| 13 |
test2: |
| 14 |
role: foo |
| 15 |
resources: {} |
| 16 |
""" |
| 17 |
) |
| 18 |
return p |
| 19 |
|
| 20 |
@pytest.fixture |
| 21 |
def short_test(tmpdir): |
| 22 |
t = tmpdir.join("test.py") |
| 23 |
t.write( |
| 24 |
""" |
| 25 |
def test(env): |
| 26 |
assert True |
| 27 |
""" |
| 28 |
) |
| 29 |
return t |
| 30 |
|
| 31 |
def test_config(short_test): |
| 32 |
with pexpect.spawn(f'pytest --traceconfig {short_test}') as spawn: |
| 33 |
spawn.expect(pexpect.EOF) |
| 34 |
assert b'labgrid.pytestplugin' in spawn.before |
| 35 |
spawn.close() |
| 36 |
assert spawn.exitstatus == 0 |
| 37 |
|
| 38 |
def test_env_fixture(short_env, short_test): |
| 39 |
with pexpect.spawn(f'pytest --lg-env {short_env} {short_test}') as spawn: |
| 40 |
spawn.expect(pexpect.EOF) |
| 41 |
spawn.close() |
| 42 |
assert spawn.exitstatus == 0 |
| 43 |
|
| 44 |
def test_env_fixture_no_logging(short_env, short_test): |
| 45 |
with pexpect.spawn(f'pytest -p no:logging --lg-env {short_env} {short_test}') as spawn: |
| 46 |
spawn.expect(pexpect.EOF) |
| 47 |
spawn.close() |
| 48 |
assert spawn.exitstatus == 0, spawn.before |
| 49 |
|
| 50 |
def test_env_env_fixture(short_env, short_test): |
| 51 |
env=os.environ.copy() |
| 52 |
env['LG_ENV'] = short_env |
| 53 |
with pexpect.spawn(f'pytest {short_test}') as spawn: |
| 54 |
spawn.expect(pexpect.EOF) |
| 55 |
spawn.close() |
| 56 |
assert spawn.exitstatus == 0 |
| 57 |
|
| 58 |
def test_env_with_junit(short_env, short_test, tmpdir): |
| 59 |
x = tmpdir.join('junit.xml') |
| 60 |
with pexpect.spawn(f'pytest --junitxml={x} --lg-env {short_env} {short_test}') as spawn: |
| 61 |
spawn.expect(pexpect.EOF) |
| 62 |
spawn.close() |
| 63 |
assert spawn.exitstatus == 0 |
| 64 |
|
| 65 |
def test_help(short_test, monkeypatch): |
| 66 |
|
| 67 |
|
| 68 |
monkeypatch.setenv("NO_COLOR", "1") |
| 69 |
|
| 70 |
with pexpect.spawn(f'pytest --help {short_test}') as spawn: |
| 71 |
spawn.expect(pexpect.EOF) |
| 72 |
assert b'--lg-coordinator=COORDINATOR_ADDRESS' in spawn.before |
| 73 |
spawn.close() |
| 74 |
assert spawn.exitstatus == 0 |
| 75 |
|
| 76 |
def test_help_coordinator(short_test): |
| 77 |
with pexpect.spawn(f'pytest --lg-coordinator=127.0.0.1:20408 --help {short_test}') as spawn: |
| 78 |
spawn.expect(pexpect.EOF) |
| 79 |
spawn.close() |
| 80 |
assert spawn.exitstatus == 0 |
| 81 |
|
| 82 |
def test_log_without_capturing(short_env, short_test, tmpdir): |
| 83 |
with pexpect.spawn(f'pytest -vv -s --lg-env {short_env} {short_test}') as spawn: |
| 84 |
spawn.expect(pexpect.EOF) |
| 85 |
spawn.close() |
| 86 |
print(spawn.before) |
| 87 |
assert spawn.exitstatus == 0 |