Migrate from Nose to pytest

This commit is contained in:
Kodi Arfer 2017-04-26 14:00:11 -07:00
parent d085fba5fe
commit d3fa375052
12 changed files with 34 additions and 59 deletions

2
.gitignore vendored
View File

@ -8,4 +8,4 @@
dist dist
.coverage .coverage
build/ build/
.noseids /.cache

View File

@ -2,7 +2,6 @@ pip_url=https://bootstrap.pypa.io/get-pip.py
python=python python=python
pip=pip pip=pip
coveralls=coveralls coveralls=coveralls
nose=nosetests
all: all:
@echo "No default step. Use setup.py" @echo "No default step. Use setup.py"
@ -41,7 +40,7 @@ endif
dev: test flake dev: test flake
test: venv test: venv
nosetests -sv pytest
tox: venv tox: venv
tox tox

13
conftest.py Normal file
View File

@ -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

View File

@ -62,12 +62,11 @@ Do this:
Test! Test!
===== =====
Tests are located in ``tests/``. We use `nose Tests are located in ``tests/``. We use `pytest <http://pytest.org>`_.
<https://nose.readthedocs.io/en/latest/>`_.
To run the tests:: To run the tests::
$ nosetests $ pytest
Write tests---tests are good! Write tests---tests are good!

View File

@ -30,7 +30,6 @@ import marshal
import struct import struct
import imp import imp
import sys import sys
import platform
import ast import ast
import os import os
import __future__ import __future__
@ -114,17 +113,13 @@ def import_file_to_module(module_name, fpath, loader=None):
module = imp.new_module(module_name) module = imp.new_module(module_name)
module.__file__ = fpath module.__file__ = fpath
code = ast_compile(_ast, fpath, "exec") code = ast_compile(_ast, fpath, "exec")
if not (platform.python_implementation() == 'PyPy' and try:
'nosetests' in sys.argv[0] and write_code_as_pyc(fpath, code)
is_package(module_name)): except (IOError, OSError):
# Nose can generate spurious errors in this specific situation. # We failed to save the bytecode, probably because of a
try: # permissions issue. The user only asked to import the
write_code_as_pyc(fpath, code) # file, so don't bug them about it.
except (IOError, OSError): pass
# 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__) eval(code, module.__dict__)
except (HyTypeError, LexException) as e: except (HyTypeError, LexException) as e:
if e.source is None: if e.source is None:

View File

@ -55,7 +55,7 @@ goto :EOF
if "%1" == "test" ( if "%1" == "test" (
:test :test
call :venv call :venv
nosetests -sv pytest -sv
goto :EOF goto :EOF
) )

View File

@ -1,6 +1,6 @@
-r requirements-travis.txt -r requirements-travis.txt
# test tools # test tools
nose pytest
tox tox
# documentation # documentation

View File

@ -1,9 +1,3 @@
[nosetests]
detailed-errors=1
with-coverage=1
cover-package=hy
nocapture=1
[wheel] [wheel]
universal = 1 universal = 1
@ -12,7 +6,6 @@ omit =
*/python?.?/* */python?.?/*
*/lib-python/?.?/*.py */lib-python/?.?/*.py
*/lib_pypy/_*.py */lib_pypy/_*.py
*/site-packages/nose/*
*/pypy/* */pypy/*
[coverage:report] [coverage:report]
@ -22,3 +15,8 @@ exclude_lines =
# We want ignore_errors so we don't get NoSource warnings for loading # We want ignore_errors so we don't get NoSource warnings for loading
# byte-compiled Hy modules. # byte-compiled Hy modules.
ignore_errors = True 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_*

View File

@ -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

View File

@ -1315,8 +1315,7 @@
(defn test-calling-module-name [] (defn test-calling-module-name []
"NATIVE: Test the calling-module-name function" "NATIVE: Test the calling-module-name function"
(assert (= (calling-module-name -1) "hy.core.language")) (assert (= (calling-module-name -1) "hy.core.language")))
(assert (= (calling-module-name 0) "tests.native_tests.language")))
(defn test-disassemble [] (defn test-disassemble []

View File

@ -1,8 +1,5 @@
;; Tests where the emitted code relies on Python 3. ;; Tests where the emitted code relies on Python 3.
;; Conditionally included in nosetests runs. ;; conftest.py skips this file when running on Python 2.
(import [hy.errors [HyCompileError]])
(defn test-exception-cause [] (defn test-exception-cause []

View File

@ -5,7 +5,7 @@ skipsdist = True
[testenv] [testenv]
commands = commands =
pip install --allow-all-external -e . pip install --allow-all-external -e .
nosetests pytest
passenv = passenv =
TERM TERM
deps = deps =