Skip to content

Use pytest instead of setup.py test #121

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
Feb 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@ python:
- 3.4
- 3.5
install:
- pip install -e . "flake8 >= 2.4.0" "Werkzeug >= 0.9" coverage coveralls
- pip install -rrequirements-dev.txt coveralls
script:
- coverage run --source sass,sassc,sassutils setup.py test
- coverage run --source sass,sassc,sassutils -m pytest sasstests.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using pytest-cov?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could, but yagni?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessary! 😁

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never used it before, maybe we could add it in a followup.

- flake8 .
after_success:
- coveralls
cache:
directories:
- $HOME/.cache/pip
11 changes: 6 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ init:
- "ECHO %PYTHON%"
- ps: "ls C:/Python*"
install:
- "git -C %APPVEYOR_BUILD_FOLDER% submodule update --init"
- "git submodule update --init"
- "%PYTHON%\\Scripts\\pip.exe --version"
- "%PYTHON%\\Scripts\\pip.exe install wheel"
- "%PYTHON%\\Scripts\\pip.exe install -e ."
- "%PYTHON%\\Scripts\\pip.exe install -rrequirements-dev.txt wheel"
build: false
test_script:
- "%PYTHON%\\python.exe -c \"import os,pprint;pprint.pprint(sorted(os.environ.items()))\""
- "%PYTHON%\\python.exe setup.py test"
- '%PYTHON%\\python.exe -c "import os, pprint; pprint.pprint(sorted(os.environ.items()))"'
- "%PYTHON%\\python.exe -m pytest sasstests.py"
after_test:
- "%PYTHON%\\python.exe setup.py bdist_wheel"
artifacts:
- path: dist\*
cache:
- '%LOCALAPPDATA%\pip\cache'
5 changes: 5 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-e .
coverage
flake8>=2.4.0
pytest
werkzeug>=0.9
37 changes: 3 additions & 34 deletions sasstests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import unittest
import warnings

import pytest
from six import PY3, StringIO, b, string_types, text_type
from werkzeug.test import Client
from werkzeug.wrappers import Response
Expand Down Expand Up @@ -230,7 +231,7 @@ def test_compile_disallows_arbitrary_arguments(self):
{'filename': 'test/a.scss'},
{'dirname': ('test', '/dev/null')},
):
with assert_raises(TypeError) as excinfo:
with pytest.raises(TypeError) as excinfo:
sass.compile(herp='derp', harp='darp', **args)
msg, = excinfo.value.args
assert msg == (
Expand Down Expand Up @@ -1172,22 +1173,9 @@ def compile_with_func(s):
return result


@contextlib.contextmanager
def assert_raises(exctype):
# I want pytest.raises, this'll have to do for now
class C:
pass

try:
yield C
assert False, 'Expected to raise!'
except exctype as e:
C.value = e


@contextlib.contextmanager
def assert_raises_compile_error(expected):
with assert_raises(sass.CompileError) as excinfo:
with pytest.raises(sass.CompileError) as excinfo:
yield
msg, = excinfo.value.args
assert msg.decode('UTF-8') == expected, (msg, expected)
Expand Down Expand Up @@ -1425,22 +1413,3 @@ def test_map_with_map_key(self):
),
'a{content:baz}\n',
)


test_cases = [
SassTestCase,
CompileTestCase,
BuilderTestCase,
ManifestTestCase,
WsgiTestCase,
DistutilsTestCase,
SasscTestCase,
CompileDirectoriesTest,
SassFunctionTest,
SassTypesTest,
CustomFunctionsTest,
]
loader = unittest.defaultTestLoader
suite = unittest.TestSuite()
for test_case in test_cases:
suite.addTests(loader.loadTestsFromTestCase(test_case))
7 changes: 0 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,6 @@ def restore_cencode():
)

install_requires = ['six']
tests_require = [
'flake8 >= 2.4.0',
'Werkzeug >= 0.9'
]


def version(sass_filename='sass.py'):
Expand Down Expand Up @@ -239,10 +235,7 @@ def run(self):
]
},
install_requires=install_requires,
tests_require=tests_require,
test_suite='sasstests.suite',
extras_require={
'tests': tests_require,
'upload_appveyor_builds': [
'twine == 1.5.0',
],
Expand Down
6 changes: 2 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
envlist = pypy, pypy3, py26, py27, py33, py34, py35

[testenv]
deps =
flake8 >= 2.4.0
Werkzeug >= 0.9
deps = -rrequirements-dev.txt
commands =
python -c 'from shutil import *; rmtree("build", True)'
python -m unittest sasstests
python -m pytest sasstests.py
flake8 .