Thanks to visit codestin.com
Credit goes to github.com

Skip to content

TST, MAINT: Add __init__.py files to tests directories. #9524

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

Merged
merged 1 commit into from
Aug 12, 2017

Conversation

charris
Copy link
Member

@charris charris commented Aug 6, 2017

This allows pytest to run with duplicate test file names. Note that
python <path-to-test-file> no longer works with this change, nor will
a simple pytest numpy, because numpy is imported from the numpy
repository. However, python runtests.py and >>> numpy.test() are
still available.

@charris
Copy link
Member Author

charris commented Aug 6, 2017

This is an alternative to #9523. Also checking that tests pass with this change.

This allows pytest to run with duplicate test file names. Note that
`python <path-to-test-file>` no longer works with this change, nor will
a simple `pytest numpy`, because numpy is imported from the numpy
repository. However, `python runtests.py` and `>>> numpy.test()` are
still available.
@charris charris force-pushed the add_init_to_test_directories branch from d507cdd to 62a12d2 Compare August 6, 2017 22:25
@charris
Copy link
Member Author

charris commented Aug 7, 2017

@eric-wieser No, that is a relative path and can't be used with nose.runmodule, which does not import the tests package, hence has no idea what .. means.

@charris
Copy link
Member Author

charris commented Aug 7, 2017

You can still import and run numpy.test(...), this only affects running a test file using run_module_suite.

EDIT: It only runs tests against installed numpy, so can be useful in test development. For testing new code, python runtests.py is still the way to go.

@charris
Copy link
Member Author

charris commented Aug 7, 2017

Not sure if this fix will work with pytest without some help. Otherwise might be stuck with only using runtests.py, as scipy is at this time.

@charris
Copy link
Member Author

charris commented Aug 7, 2017

Yeah, I can make this work for pytest also, just need the --pyargs argument. For example

pytest --pyargs numpy/f2py/tests/test_kind

That should even work with relative imports. When we are all in for pytest, can maybe change it back. Note the f2py /tests was the only test module that used relative imports after being made into a package.

@charris
Copy link
Member Author

charris commented Aug 8, 2017

Hmm, I think I will undo the last commit and just use pytest --pyarg instead. That preserves run_module_suite for downstream backwards compatibility, although I think the current change is actually an improvement,

@charris charris force-pushed the add_init_to_test_directories branch from dbcce72 to 62a12d2 Compare August 8, 2017 18:16
@charris
Copy link
Member Author

charris commented Aug 8, 2017

OK, should be ready to go, I undid last commit. I will add a release note in a future PR once I've settled a few more things.

@njsmith
Copy link
Member

njsmith commented Aug 8, 2017

FWIW when I want to run a subset of tests with pytest I usually do something like pytest numpy -k name_of_test. The downside is that it still loads all the tests and then scans them looking for ones matching that string, which can take a few seconds, but the upside is it's that the exact same test loading logic no matter what.

@charris
Copy link
Member Author

charris commented Aug 8, 2017

@njsmith The problem is that after adding the __init__ files, you cannot run pytest in the repo because it passes down through numpy. The reason the __init__ files are needed is because some test files have duplicate names.

E   ImportError: Error importing numpy: you should not try to import numpy from
E           its source directory; please exit the numpy source tree, and relaunch

@charris
Copy link
Member Author

charris commented Aug 12, 2017

Gotta happen eventually, so putting this in.

@charris charris merged commit 965890d into numpy:master Aug 12, 2017
@charris charris deleted the add_init_to_test_directories branch August 14, 2017 23:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants