astropy/astropy — pull request #1962 by mdboom (2014-01-14 13:45:37+00:00)
Title: Test with and without unicode literals by parsing with `ast`

This is an alternative to #1956, that uses the `ast` module to recompile the source files in different `__future__` modes, and to modify the source so that byte strings with non-ascii characters are correctly decoded.

It has the following advantages, IMO:

- It doesn't touch files on disk, so it should work equally well in `setup.py test` and `astropy.test()` modes.
- Tracebacks should point back to the original files, so it is easier to fix errors when they occur.

I've only started the process of making sure everything works in these modes. The fixes fall into the following categories:

- Use `tests.helpers.catch_warnings` rather than `warnings.catch_warnings`, `pytest.recwarn` or `logger.log_to_list` since none of the latter reset the warning state completely, meaning that running the same test twice will result in missing warnings.
- Move `pytest.fixture` definitions to a central `conftest.py` file, since `pytest` doesn't like them to be defined twice.
- Set `coding` tokens on all test files containing Unicode and *not* using unicode escapes, since the latter won't work when `unicode_literals` is off.
- Use `print_function` everywhere, since this now turns it on all the time.

Open questions:

- This allows for blacklisting certain files that we don't want to run in both modes (for example, the long running coordinate accuracy tests, and also for pickling tests which get confused by compiling code twice in the same "module namespace"). Should we instead make this a whitelist?

Todo:

* [ ] add an option to `setup.py test` and `astropy.test` to turn this off (to save run time)
* [ ] get all tests working again