Skip to content

Commit

Permalink
Invoke test runner at a more granular level for pypy shard. (#513)
Browse files Browse the repository at this point in the history
Fixes #497
  • Loading branch information
kwlzn authored Jun 9, 2018
1 parent 541a747 commit 657a837
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ install:
- pip install -U tox "setuptools<34"

script:
- tox -v
- ./scripts/ci.sh
10 changes: 10 additions & 0 deletions scripts/ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

set -euo pipefail

if [[ "$TOXENV" == "pypy" ]]; then
echo "pypy shard detected. invoking workaround for https://github.com/travis-ci/travis-ci/issues/9706"
tox -e list-tests | grep ^"RUNNABLE" | grep -v "tests/test_integration.py" | awk -F'\t' '{print $NF}' | xargs -L1 tox -v
else
tox -v
fi
37 changes: 37 additions & 0 deletions scripts/list_tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python

import sys
import pytest


class Collector(object):

RUN_INDIVIDUALLY = ['tests/test_pex.py']

def __init__(self):
self._collected = set()

def iter_collected(self):
for collected in sorted(self._collected):
yield collected

def pytest_collectreport(self, report):
if report.failed:
raise pytest.UsageError('Errors during collection, aborting!')

def pytest_collection_modifyitems(self, items):
for item in items:
test_file = item.location[0]
if test_file in self.RUN_INDIVIDUALLY:
self._collected.add(item.nodeid)
else:
self._collected.add(test_file)


collector = Collector()
rv = pytest.main(['--collect-only'] + sys.argv[1:], plugins=[collector])

for test_target in collector.iter_collected():
print('RUNNABLE\t"{}"'.format(test_target))

sys.exit(rv)
8 changes: 6 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ deps =
wheel==0.29.0
packaging==16.8
setuptools<34.0
py27: mock
pypy: mock
list-tests: mock==2.0.0
py27: mock==2.0.0
pypy: mock==2.0.0
run: requests
requests: requests
requests: responses
Expand Down Expand Up @@ -55,6 +56,9 @@ commands =
# This is necessary due to https://bitbucket.org/hpk42/tox/issue/175/cant-do-substitution-base-commands
bash scripts/coverage.sh

[testenv:list-tests]
commands = python scripts/list_tests.py

[testenv:py27-coverage]
commands = {[integration]commands}

Expand Down

0 comments on commit 657a837

Please sign in to comment.