-
Notifications
You must be signed in to change notification settings - Fork 532
Pytest #1722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pytest #1722
Conversation
Current coverage is 71.11% (diff: 62.06%)@@ master #1722 diff @@
==========================================
Files 1030 1028 -2
Lines 51927 50608 -1319
Methods 0 0
Messages 0 0
Branches 7346 7331 -15
==========================================
- Hits 36919 35988 -931
+ Misses 13883 13495 -388
Partials 1125 1125
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great effort! Thanks a lot!
@@ -11,7 +10,7 @@ def test_NormalizeProbabilityMapSet_inputs(): | |||
|
|||
for key, metadata in list(input_map.items()): | |||
for metakey, value in list(metadata.items()): | |||
yield assert_equal, getattr(inputs.traits()[key], metakey), value | |||
assert getattr(inputs.traits()[key], metakey) == value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are these changes done in the tools/checkspecs.py file? If not, they will go away with make specs
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes the tools/checkspecs.py has changed, all auto tests are generated by running python2 tools/checkspecs.py
I know this PR is almost impossible to read, I have another branch pytest_oldAutoTests (and try to keep updated) without new auto tests, so I can compare other changes:
https://github.com/djarecka/nipype/compare/master...djarecka:pytest_oldAutoTests?expand=1#diff-e661fcf16301968039679532e45d0224
timeout: 2600 | ||
- docker run -v /etc/localtime:/etc/localtime:ro -e FSL_COURSE_DATA="/root/examples/nipype-fsl_course_data" -v ~/examples:/root/examples:ro -v ~/scratch:/scratch -w /root/src/nipype nipype/nipype_test:py27 /usr/bin/run_nosetests.sh py27 : | ||
timeout: 5200 | ||
# - docker run -v /etc/localtime:/etc/localtime:ro -e FSL_COURSE_DATA="/root/examples/nipype-fsl_course_data" -v ~/examples:/root/examples:ro -v ~/scratch:/scratch -w /root/src/nipype nipype/nipype_test:py35 /usr/bin/run_nosetests.sh py35 : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually disabling tests in CircleCI. Could you modify run_nosetests.sh
(https://github.com/nipy/nipype/blob/master/docker/circleci/run_nosetests.sh) so that it calls py.test inside?
If you rename that file, make sure it starts with the prefix run_
so it is automatically added in the docker image.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I know :) I was still modifying and testing on other branch without running all examples etc. (so it doesn't run 4h). I've just pushed a new version that runs run_pytests.sh
(plus all examples; so let's see if it's ok)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my run_pytest.sh
is far from being perfect, I'd need some help (left some notes within the file). Mostly I'm not sure if I should install pytest and other library using this file or docker containers might be changed. I also don't know how to recreate the codecov functionality: for now I removed xml files and testing pytest-cov.
@satra : Thanks, will read. In general, I'm using pytest-cov: https://github.com/djarecka/nipype/blob/pytest/docker/circleci/run_pytests.sh#L33 |
conda update --all -y python=$TRAVIS_PYTHON_VERSION pytest && | ||
pip install pytest-raisesregexp && | ||
pip install pytest-cov && | ||
pip install click && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is unnecessary - should happen with the requirements.txt
file.
pip install -U pytest | ||
pip install pytest-raisesregexp | ||
pip install pytest-cov | ||
pip install click |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
click
is a nipype requirement. and so should pytest
now. these should be updated in nipype/info.py
and *requirements.txt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
had to add click installation once I've started testing doctest. Had errors from nipype/scripts/cli.py
and nipype/scripts/utils.py
.
When I run containers on my laptop I do have an import error when I try import click
|
||
class TestTSNR(unittest.TestCase): | ||
#NOTE_dj: haven't removed mock (have to understand better) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can remove this note - mock
is used to simulate some interaction that may not exist on the system.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
however if it's not used in a particular file, it should be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had this note, since I was thinking about trying to use pytest mock and monkeypatching instead of the mock library. I will remove the note and keep the library for now. Can try to change it in different PR, once I understand pytest better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't been super happy with the mock library, so if you do check out pytest mock, tell me what you think!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, I'll give a second try. Since I've never used any mocking or patching, I had problem with understanding how important the differences between the libraries might be for the project.
I will open a new PR for it, so it will be easier to review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool--it's not a priority or anything :)
@djarecka - this looks great and is almost there. if you can:
we can merge it. |
6f2f9cb
to
112ffc3
Compare
@satra:
some issues that I still don't know how to solve (but I believe PR can me merged regardless):
|
we should change the docker files as well. |
@satra: can remove Let me know, if you had something else/more in mind. |
i think configparser may need to stay for py27 |
…arametrize, fixture, skipif, shortening a few functions
…ere not tested by travis)
…ng asserts, fixture for creating files, some problems with exceptions
… but adding pdb.set_trace() or running py.test -s could change the output of the test
…st with and without output capturing should work
…ert, not yield asser_equal; all test_auto* were changed (running python2 tools/checkspec
…ype, have some errors/fails that could be related to yield)
…ircle run pip install requirements.txt first (circle is building new containers that depend on the current version of the file)
…t_equal from numpy is used; small cleaning of imports that are not used
… pytest testing framework
@satra all tests were passed after I changed Dockerfiles yesterday, but today I've discovered that my PR can't be merged automatically, since one new test was merged. I rebased again and running tests, but this PR will always have conflict whenever any single test will be changed on the master. |
@djarecka - we will merge this as soon as circle passes. |
Hurray! Gratulacje!
…On Dec 10, 2016 6:08 AM, "Satrajit Ghosh" ***@***.***> wrote:
Merged #1722 <#1722>.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1722 (comment)>, or mute the
thread
<https://github.com/notifications/unsubscribe-auth/AAOkp5muSi-gdnlPt7GAOh6Sgtk9PrRbks5rGrJ1gaJpZM4K8y3Y>
.
|
@chrisfilo: :-) |
import nipype.interfaces.freesurfer as freesurfer | ||
|
||
|
||
def create_files_in_directory(): | ||
@pytest.fixture() | ||
def create_files_in_directory(request): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this fixture be creating in nipype.testing and imported from there. seems like this gets repeated in a couple of files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it can be, let me do it in a separate PR, I will review some other fixtures. I believe this is not the only one that is often repeated
@@ -1,3 +1,6 @@ | |||
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT | |||
from nipype.testing import assert_equal | |||
from nipype.interfaces.fsl.dti import BEDPOSTX | |||
|
|||
#NOTE_dj: this test has only import statements | |||
#NOTE_dj: this is not a AUTO test! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is ok. it is used only to ensure that the autotest is not written. the BEDPOSTX interface that's instantiated depends on the version of FSL installed in the system.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've restored the file, but change the comment. However, I did not notice any new test_auto_BEDPOSTX .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checking this issue, I've discovered that I have one auto test that is untracked - nipype/algorithms/tests/test_auto_ACompCor.py
. You don't have it?
@@ -46,11 +45,13 @@ def test_filmgls(): | |||
use_pava=dict(argstr='--pava',), | |||
) | |||
instance = FILMGLS() | |||
#NOTE_dj: don't understand this test: | |||
#NOTE_dj: IMO, it should go either to IF or ELSE, instance doesn't depend on any parameters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar to BEDPOSTX
, the specific FILMGLS
class depends on the instance of FSL.
@@ -1,3 +1,5 @@ | |||
# -*- coding: utf-8 -*- | |||
from nipype.testing import assert_equal | |||
from nipype.interfaces.fsl.dti import XFibres | |||
|
|||
#NOTE_dj: this test contains import statements only... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as BEDPOSTX
@skipif(no_fsl) # skip if fsl not installed) | ||
|
||
#NOTE_dj: a function, e.g. "no_fsl" always gives True, shuld always change to no_fsl in pytest skipif | ||
#NOTE_dj: removed the IF statement, since skipif is used? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good.
|
||
|
||
# Test AWS creds read from env vars | ||
@skipif(noboto3 or not fakes3) | ||
#NOTE_dj: noboto3 and fakes3 are not used in this test, is skipif needed for other reason? | ||
@pytest.mark.skipif(noboto3 or not fakes3, reason="boto3 or fakes3 library is not available") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the test should not be run if boto or fakes3 are not available. they don't have to be used in the test.
def test_jsonsink(): | ||
import simplejson | ||
import os | ||
#NOTE_dj: I split the test_jsonsink, didn't find connection between two parts, could easier use parametrize for the second part |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
#NOTE_dj: can we change the imports, so it's more clear where the function come from | ||
#NOTE_dj: in ...testing there is simply from numpy.testing import * | ||
from ...testing import utils | ||
from numpy.testing import assert_almost_equal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better.
from .. import nilearn as iface | ||
from ...pipeline import engine as pe | ||
|
||
import pytest, pdb |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is pdb being used?
from ... import engine as pe | ||
from ....interfaces import base as nib | ||
|
||
#NOTE_dj: I combined some tests that didn't have any extra description | ||
#NOTE_dj: some other test can be combined but could be harder to read as examples of usage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok.
@djarecka - i can't find the comments you are posting for some reason - but i receive emails. auto-tests are only generated when a corresponding named test is not available. |
@satra : my point was that after removing And independent question was about |
@satra : the reason why I haven't seen any difference after removing |
I removed
nose
andunittest
libraries; and rewrote the tests topytest
. I still keptmock
library in a few tests. I tried to not change the tests coverage, they should tests exactly the same functionality. However,py.test
stops execution after the firstassert
statement that fails.This is still not completely finished:
xfail
, they wereskipif(True)
before.circle.yml
runsrun_pytests.py
instead ofrun_nosetests.py
,run_pytests.py
needs to be improvedI also slightly adjusted docstrings so doctests with
pytest
can be run.