Permalink
Browse files

Migrate from Nose to pytest

  • Loading branch information...
Kodiologist committed Apr 26, 2017
1 parent d085fba commit d3fa375052e08b4572f26fb3fd4807e1d58ad315
Showing with 34 additions and 59 deletions.
  1. +1 −1 .gitignore
  2. +1 −2 Makefile
  3. +13 −0 conftest.py
  4. +2 −3 docs/hacking.rst
  5. +7 −12 hy/importer.py
  6. +1 −1 make.bat
  7. +1 −1 requirements-dev.txt
  8. +5 −7 setup.cfg
  9. +0 −25 tests/__init__.py
  10. +1 −2 tests/native_tests/language.hy
  11. +1 −4 tests/native_tests/py3_only_tests.hy
  12. +1 −1 tox.ini
@@ -8,4 +8,4 @@
dist
.coverage
build/
.noseids
/.cache
@@ -2,7 +2,6 @@ pip_url=https://bootstrap.pypa.io/get-pip.py
python=python
pip=pip
coveralls=coveralls
nose=nosetests
all:
@echo "No default step. Use setup.py"
@@ -41,7 +40,7 @@ endif
dev: test flake
test: venv
nosetests -sv
pytest
tox: venv
tox
@@ -0,0 +1,13 @@
import _pytest
import hy
from hy._compat import PY3
def pytest_collect_file(parent, path):
if (path.ext == ".hy"
and "/tests/native_tests/" in path.dirname + "/"
and path.basename != "__init__.hy"
and not ("py3_only" in path.basename and not PY3)):
m = _pytest.python.pytest_pycollect_makemodule(path, parent)
# Spoof the module name to avoid hitting an assertion in pytest.
m.name = m.name[:-len(".hy")] + ".py"
return m
@@ -62,12 +62,11 @@ Do this:
Test!
=====
Tests are located in ``tests/``. We use `nose
<https://nose.readthedocs.io/en/latest/>`_.
Tests are located in ``tests/``. We use `pytest <http://pytest.org>`_.
To run the tests::
$ nosetests
$ pytest
Write tests---tests are good!
@@ -30,7 +30,6 @@
import struct
import imp
import sys
import platform
import ast
import os
import __future__
@@ -114,17 +113,13 @@ def import_file_to_module(module_name, fpath, loader=None):
module = imp.new_module(module_name)
module.__file__ = fpath
code = ast_compile(_ast, fpath, "exec")
if not (platform.python_implementation() == 'PyPy' and
'nosetests' in sys.argv[0] and
is_package(module_name)):
# Nose can generate spurious errors in this specific situation.
try:
write_code_as_pyc(fpath, code)
except (IOError, OSError):
# We failed to save the bytecode, probably because of a
# permissions issue. The user only asked to import the
# file, so don't bug them about it.
pass
try:
write_code_as_pyc(fpath, code)
except (IOError, OSError):
# We failed to save the bytecode, probably because of a
# permissions issue. The user only asked to import the
# file, so don't bug them about it.
pass
eval(code, module.__dict__)
except (HyTypeError, LexException) as e:
if e.source is None:
@@ -55,7 +55,7 @@ goto :EOF
if "%1" == "test" (
:test
call :venv
nosetests -sv
pytest -sv
goto :EOF
)
@@ -1,6 +1,6 @@
-r requirements-travis.txt
# test tools
nose
pytest
tox
# documentation
@@ -1,9 +1,3 @@
[nosetests]
detailed-errors=1
with-coverage=1
cover-package=hy
nocapture=1
[wheel]
universal = 1
@@ -12,7 +6,6 @@ omit =
*/python?.?/*
*/lib-python/?.?/*.py
*/lib_pypy/_*.py
*/site-packages/nose/*
*/pypy/*
[coverage:report]
@@ -22,3 +15,8 @@ exclude_lines =
# We want ignore_errors so we don't get NoSource warnings for loading
# byte-compiled Hy modules.
ignore_errors = True
[tool:pytest]
# Be sure to include Hy test functions whose names end with "?",
# which will be mangled to begin with "is_".
python_functions=test_* is_test_*
@@ -1,25 +0,0 @@
import hy # noqa
from hy._compat import PY3
from .native_tests.cons import * # noqa
from .native_tests.defclass import * # noqa
from .native_tests.mathematics import * # noqa
from .native_tests.native_macros import * # noqa
from .native_tests.quote import * # noqa
from .native_tests.language import * # noqa
from .native_tests.unless import * # noqa
from .native_tests.when import * # noqa
from .native_tests.with_decorator import * # noqa
from .native_tests.core import * # noqa
from .native_tests.sharp_macros import * # noqa
from .native_tests.operators import * # noqa
from .native_tests.with_test import * # noqa
from .native_tests.extra.anaphoric import * # noqa
from .native_tests.contrib.loop import * # noqa
from .native_tests.contrib.walk import * # noqa
from .native_tests.contrib.multi import * # noqa
from .native_tests.contrib.sequences import * # noqa
from .native_tests.contrib.hy_repr import * # noqa
if PY3:
from .native_tests.py3_only_tests import * # noqa
@@ -1315,8 +1315,7 @@
(defn test-calling-module-name []
"NATIVE: Test the calling-module-name function"
(assert (= (calling-module-name -1) "hy.core.language"))
(assert (= (calling-module-name 0) "tests.native_tests.language")))
(assert (= (calling-module-name -1) "hy.core.language")))
(defn test-disassemble []
@@ -1,8 +1,5 @@
;; Tests where the emitted code relies on Python 3.
;; Conditionally included in nosetests runs.
(import [hy.errors [HyCompileError]])
;; conftest.py skips this file when running on Python 2.
(defn test-exception-cause []
@@ -5,7 +5,7 @@ skipsdist = True
[testenv]
commands =
pip install --allow-all-external -e .
nosetests
pytest
passenv =
TERM
deps =

0 comments on commit d3fa375

Please sign in to comment.