dcos-launch icon indicating copy to clipboard operation
dcos-launch copied to clipboard

Pytest support

Open margaret opened this issue 8 years ago • 1 comments

for https://jira.mesosphere.com/browse/QUALITY-1662, optionally provide file handle to write output of the launcher's test method, defaulting to stdout

margaret avatar Dec 07 '17 21:12 margaret

@mellenburg I think right now it's the way I'm mocking things that's wrong, not the main change, but still trying to confirm and fix. This works:

import subprocess
import sys
import traceback

with open('pytest_logs_fail.txt', 'w') as f:
    try:
        result = subprocess.check_call(['pytest', '-s', '-vv'], stdout=f)
        print(result)
    except Exception as e:
        print("!!!!!!")
        tb = traceback.format_exc()
        msg = '\n\nPytest failed!\n{}\n'.format(tb)
        f.write(msg)

Running this :arrow_up: writes this to the file:

============================= test session starts ==============================
platform darwin -- Python 3.5.0, pytest-3.1.3, py-1.4.34, pluggy-0.4.0 -- /Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5
cachedir: .cache
rootdir: /Users/margaretsy/mesosphere/sandbox/testing-tests, inifile:
collecting ... collected 4 items

test_foo.py::test_times_two[2-22] PASSED
test_foo.py::test_times_two[2-4] PASSED
test_foo.py::test_times_two[input2-expected2] PASSED
test_foo.py::test_shitty_times_two FAILED

=================================== FAILURES ===================================
____________________________ test_shitty_times_two _____________________________

    def test_shitty_times_two():
>       assert shitty_times_two(2) == 4
E       assert 4.2 == 4
E        +  where 4.2 = shitty_times_two(2)

test_foo.py:14: AssertionError
====================== 1 failed, 3 passed in 0.03 seconds ======================


Pytest failed!
Traceback (most recent call last):
  File "log_to_file.py", line 7, in <module>
    result = subprocess.check_call(['pytest', '-s', '-vv'], stdout=f)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 584, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['pytest', '-s', '-vv']' returned non-zero exit status 1

margaret avatar Dec 08 '17 01:12 margaret