Skip to content

Commit 53e84f3

Browse files
author
Ramiro Morales
committed
Finish migrating tests infrastructure to py.test.
Thanks Marc Abramowitz for most of the effort in actual porting.
1 parent 53f904a commit 53e84f3

File tree

5 files changed

+47
-110
lines changed

5 files changed

+47
-110
lines changed

README_building_and_developing.rst

+12-13
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ Testing
125125

126126
You will need to install two additional packages for testing::
127127

128-
easy_install nose SQLAlchemy
128+
easy_install SQLAlchemy
129129

130130
You should build the package with::
131131

@@ -134,33 +134,32 @@ You should build the package with::
134134
You need to setup a ``tests.cfg`` file in ``tests/`` with the correct DB
135135
connection information for your environement::
136136

137-
cd tests/
138-
cp tests.cfg.tpl tests.cfg
139-
vim|emacs|notepad tests.cfg
137+
cp tests/tests.cfg.tpl tests/tests.cfg
138+
vim|emacs|notepad tests/tests.cfg
140139

141140
To run the tests::
142141

143-
cd tests/
144-
nosetests
142+
cd tests # optional
143+
py.test
145144

146145
Which will go through and run all the tests with the settings from the ``DEFAULT``
147146
section of ``tests.cfg``.
148147

149148
To run with a different ``tests.cfg`` section::
150149

151-
nosetests --pymssql-section=<secname>
150+
py.test --pymssql-section=<secname>
152151

153152
example::
154153

155-
nosetests --pymssql-section=AllTestsWillRun
154+
py.test --pymssql-section=AllTestsWillRun
156155

157156
to avoid slow tests::
158157

159-
nosetests -a '!slow'
158+
py.test -m "not slow"
160159

161160
to select specific tests to run::
162161

163-
nosetests test_types.py
164-
nosetests test_types.py test_sprocs.py
165-
nosetests test_types.py:TestTypes
166-
nosetests test_types.py:TestTypes.test_image
162+
py.test tests/test_types.py
163+
py.test tests/test_types.py tests/test_sprocs.py
164+
py.test tests/test_types.py::TestTypes
165+
py.test tests/test_types.py::TestTypes::test_image

pytest.ini

+2
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ addopts =
88
-rfEsxX
99
# --junitxml=junit.xml
1010
# --cov=pymssql --cov-report=xml --cov-report=term-missing
11+
markers =
12+
slow: Mark a pymssql test as slow (usually taking more one second or more).

setup.py

+26-16
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,18 @@
3232
# running python setup.py test (see
3333
# http://www.eby-sarna.com/pipermail/peak/2010-May/003357.html)
3434
try:
35-
import multiprocessing
35+
import multiprocessing # NOQA
3636
except ImportError:
3737
pass
3838

3939
sys.path.append(osp.join(osp.dirname(__file__), '.pyrex'))
4040

4141
try:
4242
from setuptools import setup, Extension
43-
from setuptools.command.develop import develop as STDevelopCmd
4443
except ImportError:
4544
import ez_setup
4645
ez_setup.use_setuptools()
4746
from setuptools import setup, Extension
48-
from setuptools.command.develop import develop as STDevelopCmd
4947

5048
# Work around Setuptools' broken (Cython-unaware) monkeypatching
5149
# to support Pyrex. This monkeypatching makes the Cython step get skipped if
@@ -59,6 +57,9 @@
5957
else:
6058
Extension.__init__ = setuptools.dist._get_unpatched(setuptools.extension.Extension).__init__
6159

60+
from setuptools.command.test import test as TestCommand
61+
62+
6263
ROOT = osp.abspath(osp.dirname(__file__))
6364

6465
def fpath(*parts):
@@ -337,12 +338,6 @@ def release_unix(self):
337338
sdist.ensure_finalized()
338339
sdist.run()
339340

340-
class DevelopCmd(STDevelopCmd):
341-
def run(self):
342-
# add in the nose plugin only when we are using the develop command
343-
self.distribution.entry_points['nose.plugins'] = ['pymssql_config = tests.nose_plugin:ConfigPlugin']
344-
STDevelopCmd.run(self)
345-
346341
def ext_modules():
347342
if have_c_files:
348343
source_extension = 'c'
@@ -362,6 +357,26 @@ def ext_modules():
362357
),
363358
]
364359

360+
361+
class PyTest(TestCommand):
362+
user_options = [('pytest-args=', 'a', "Arguments to pass to py.test")]
363+
364+
def initialize_options(self):
365+
TestCommand.initialize_options(self)
366+
self.pytest_args = None
367+
368+
def finalize_options(self):
369+
TestCommand.finalize_options(self)
370+
self.test_args = []
371+
self.test_suite = True
372+
373+
def run_tests(self):
374+
#import here, cause outside the eggs aren't loaded
375+
import pytest
376+
errno = pytest.main(self.pytest_args)
377+
sys.exit(errno)
378+
379+
365380
setup(
366381
name = 'pymssql',
367382
version = extract_version(),
@@ -379,7 +394,7 @@ def ext_modules():
379394
'build_ext': build_ext,
380395
'clean': clean,
381396
'release': release,
382-
'develop': DevelopCmd
397+
'test': PyTest,
383398
},
384399
classifiers=[
385400
"Development Status :: 5 - Production/Stable",
@@ -402,12 +417,7 @@ def ext_modules():
402417
],
403418
zip_safe = False,
404419
setup_requires=['setuptools_git'],
405-
tests_require=['nose', 'unittest2'],
406-
test_suite='nose.collector',
420+
tests_require=['pytest', 'unittest2'],
407421
ext_modules = ext_modules(),
408422

409-
# don't remove this, otherwise the customization above in DevelopCmd
410-
# will break. You can safely add to it though, if needed.
411-
entry_points = {}
412-
413423
)

tests/helpers.py

+7-17
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,16 @@
22
from os import path
33
import time
44

5-
try:
6-
from nose.tools import eq_
7-
from nose.plugins.skip import SkipTest
8-
from nose.plugins.attrib import attr
5+
import pytest
96

10-
def skip_test(reason='No reason given to skip_test'):
11-
raise SkipTest(reason)
7+
def eq_(a, b):
8+
assert a == b
129

13-
mark_slow = attr('slow')
14-
except ImportError:
15-
import pytest
10+
def skip_test(reason='No reason given to skip_test'):
11+
pytest.skip(reason)
1612

17-
def eq_(a, b):
18-
assert a == b
19-
20-
def skip_test(reason='No reason given to skip_test'):
21-
pytest.skip(reason)
22-
23-
def mark_slow(f):
24-
return f
13+
def mark_slow(f):
14+
return f
2515

2616
import _mssql
2717
import pymssql

tests/nose_plugin.py

-64
This file was deleted.

0 commit comments

Comments
 (0)