Skip to content

Commit

Permalink
pytest: Get coverage inside and outside plugins working
Browse files Browse the repository at this point in the history
  • Loading branch information
cdecker committed Aug 28, 2020
1 parent f43414d commit 12fdd14
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
7 changes: 7 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[run]
branch = True
data_file = /tmp/.coverage
parallel = True
omit =
*.direnv*
debug = multiproc
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,3 @@ before_install:

script:
.travis/build.sh

after_success:
- codecov --env COMPAT,DEVELOPER,EXPERIMENTAL_FEATURES
2 changes: 0 additions & 2 deletions .travis/bin/python3

This file was deleted.

26 changes: 7 additions & 19 deletions .travis/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ set -e

CWD=$(pwd)
export SLOW_MACHINE=1
export PATH="$HOME/.local/bin:$PATH"
export PATH="$HOME/.local/bin:dependencies/bin:$PATH"
export PYTEST_PAR=10
export TEST_DEBUG=1
export LIGHTNING_VERSION=${LIGHTNING_VERSION:-master}
Expand All @@ -29,7 +29,7 @@ pip3 install --user --quiet \
psycopg2-binary>=2.8.3 \
pytest-timeout==1.3.3 \
pytest-xdist==1.30.0 \
pytest-cov \
pytest-cover \
coverage \
codecov \
mrkd==0.1.6
Expand All @@ -46,7 +46,7 @@ git clone --recursive https://github.com/ElementsProject/lightning.git /tmp/ligh
cd /tmp/lightning
git checkout "$LIGHTNING_VERSION"
./configure --disable-valgrind
make -j 8
make -j 16 > /dev/null
)
echo 'travis_fold:end:script.2'

Expand All @@ -58,26 +58,14 @@ find . -name requirements.txt -exec pip3 install --quiet --upgrade --user -r {}
pip install -U pyln-testing>=0.8.2 pyln-client>=0.8.2
echo 'travis_fold:end:script.3'

# Add the local bitcoind bin dir so we can start and control it:
export PATH="$CWD/.travis/bin:$CWD/dependencies/bin:$CWD/dependencies/usr/local/bin/:$PATH"

# Add the directory we put the newly compiled lightningd in
export PATH="/tmp/lightning/lightningd/:$PATH"

# Enable coverage reporting from inside the plugin. This is done by adding a
# wrapper called python3 that internally just calls `coverage run` and stores
# the coverage output in `/tmp/.coverage.*` from where we can pick the details
# up again.
export PATH="$CWD/.travis/bin:$PATH"

# Force coverage to write files in $CWD
export COVERAGE_FILE="$CWD/.coverage"
export COVERAGE_RCFILE="$CWD/.coveragerc"

# Make sure we use the correct python3 wrapper (the one that calls coverage
# internally).
which python3

rm /tmp/.coverage.* .coverage.tmp .coverage || true
export PYTHONPATH="$CWD"
pytest -vvv --timeout=550 --timeout_method=thread -p no:logging -n 5 --cov

pytest -vvv --timeout=550 --timeout_method=thread -p no:logging -n 5
ls -lha
codecov --env COMPAT,DEVELOPER,EXPERIMENTAL_FEATURES
10 changes: 10 additions & 0 deletions sitecustomize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import coverage
cov = coverage.process_startup()

if cov is not None:
import atexit
def stop():
cov.stop()
cov.save()

atexit.register(stop)

0 comments on commit 12fdd14

Please sign in to comment.