Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Pytest support #74

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open

Pytest support #74

wants to merge 17 commits into from

Conversation

margaret
Copy link
Contributor

@margaret margaret commented Dec 7, 2017

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
Copy link
Contributor Author

margaret commented Dec 8, 2017

@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 ⬆️ 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 margaret force-pushed the pytest_support branch 2 times, most recently from a339694 to 85d746e Compare December 18, 2017 21:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant