-
Notifications
You must be signed in to change notification settings - Fork 25
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
Fix tox with C-extension #310
Conversation
9e5ec58
to
7154544
Compare
7154544
to
090fe5b
Compare
With or without |
c10d4e3
to
090fe5b
Compare
tox.ini
Outdated
@@ -53,9 +52,6 @@ extras = | |||
alldeps: all | |||
|
|||
commands = | |||
# FIXME: Not sure why need this for tox to see the C-ext | |||
python setup.py build_ext --inplace | |||
# End of FIXME | |||
pip freeze | |||
!cov: pytest --pyargs synphot {toxinidir}/docs {posargs} |
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.
@jdavies-st , I do have --pyargs
here. Am I using it wrong?
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.
With changedir
commented out above, because you are running pytest --pyargs
from within a directory that has synphot
as a subdir, every import synphot
will import it from the local checkout, not the installed location, following normal python import rules that always imports the local dir thing before checking python path.
I converted this to draft PR for now. FYI. |
Codecov Report
@@ Coverage Diff @@
## master #310 +/- ##
=======================================
Coverage 94.85% 94.85%
=======================================
Files 14 14
Lines 1983 1983
=======================================
Hits 1881 1881
Misses 102 102 Continue to review full report at Codecov.
|
@@ -4,8 +4,9 @@ testpaths = "synphot" "docs" | |||
norecursedirs = build docs/_build synphot/src | |||
astropy_header = true | |||
doctest_plus = enabled | |||
doctest_rst = true |
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.
Huh, why this addition, is addopts = --doctest-rst
not enough?
tox.ini
Outdated
# Run the tests in a temporary directory to make sure that we don't import | ||
# package from the source tree | ||
#changedir = .tmp/{envname} | ||
changedir = {homedir} |
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.
Does it have to be homedir
? Did changedir = .tmp/{envname}
not work?
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.
Does it matter?
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, homedir
might be pre-populated with stuff. .tmp/{envname}
is clean.
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 point is that tests do run in the install directory unlike what it was before - the source directory. Whether they run in
home/.tox/py39.../lib/python3.9/site-packages/synphot
or
chdir .tmp/py39env
../../home/.tox/py39env/lib/python3.9/site-packages/synphot
does it make a difference?
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'd rather you change it to .tmp/{envname}
anyway, if either one works. That is what astropy
is using and easier for me to copy paste from upstream in the future.
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.
Done
tox.ini
Outdated
# FIXME: Seems like using -c option with multiline Pytest is broken: see | ||
# https://github.com/tox-dev/tox-travis/issues/146 | ||
# at the very least on CI - it runs fine locally on MacOSX. | ||
cov: pytest --rootdir={toxinidir} -c {toxinidir}/setup.cfg --pyargs synphot --cov={envsitepackagesdir}/synphot --cov-config={toxinidir}/setup.cfg {posargs} --cov-report xml:{toxinidir}/coverage.xml |
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 you explain why the changes here (besides tox-dev/tox-travis#146)?
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.
Not really. It seems like the directory in which pytest
is going to run depends on a combination of factors such as rootdir
, location of the config for pytest, etc. I was just lucky enough to guess the right incantation.
be8832e
to
208bf4b
Compare
db483f0
to
5bcdad0
Compare
It was from scientific-python/pytest-doctestplus#108 but I don't remember now if it was added as a precaution or I needed it. You can try remove it and see. |
d735c8c
to
16107c6
Compare
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 feel like this might have added some stuff that is unnecessary. I'll play with this a bit and report back. Thanks for investigating!
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.
So... I look at the logs here and noticed that it is not actually running the doctest in the docs
folder.
And... Purely by accident, I found out that the presence of conftest.py
in the root directory messes up tox
. So, simply by removing it (#313), tox
picks up the installed version again and is also running the doctest. Though I hate to lose the really informative pytest
header, I think removing conftest.py
at the root dir is the more correct way to go. What do you think, @mcara and @jdavies-st ?
Also see spacetelescope/jdaviz#583 .
Actually... Maybe you hit the gold mine with |
Like what? |
Well, look at the diff. |
What specifically about diff worries you? I just removed your workaround that you have marked with |
That is, this PR allows running unit tests on installed package instead of the source directory with the package build in place (as it is currently done). All tests seem to be passing and running from the installed directory. However, I see that #314 is achieving the same with other added benefits like picking up |
For background info, see #295 and related issues/PRs.
This PR avoids building the package in its own directory when running
tox
. This is done by changing import mode inpytest
(seesetup.cfg
) and switching to absolute imports in test modules (which is a good thing anyway).The only test that is failing is doc test when trying to import
synphot
due to relative import of_astropy_init
- you will see this in failing tests.CC: @pllim