-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
squashed: switch to pytest for quickstarted projects
- Loading branch information
1 parent
c93d006
commit d8c9f69
Showing
20 changed files
with
501 additions
and
668 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,5 @@ TGTest-* | |
devtools/tests/data/ | ||
dist/ | ||
build/ | ||
\#*\# | ||
.\#* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ python: | |
- "3.6" | ||
- "3.7" | ||
- "3.8" | ||
- "3.9-dev" | ||
|
||
install: | ||
- "pip install --upgrade setuptools" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# refer to https://coverage.readthedocs.io/en/latest/config.html | ||
[run] | ||
source = {{package}} | ||
|
||
[report] | ||
show_missing = True | ||
|
||
# if you don't omit tests directory you have more chances of seeing two tests with same name | ||
omit = | ||
setup.py | ||
migration/* | ||
# tests/* | ||
|
||
# fail test suite if coverage drops below 100% (if you uncomment it) | ||
# this does not work for nosetests, set it in setup.cfg (min-cover-percentage) | ||
# fail_under = 100 | ||
|
||
# Don’t include files in the report that are 100% covered files | ||
skip_covered = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 0 additions & 92 deletions
92
devtools/gearbox/quickstart/template/+package+/tests/__init__.py_tmpl
This file was deleted.
Oops, something went wrong.
67 changes: 67 additions & 0 deletions
67
devtools/gearbox/quickstart/template/+package+/tests/_conftest/app.py_tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import pytest | ||
from webtest import TestApp as WebTestApp # rename due to pytest warning | ||
from paste.deploy import loadapp, appconfig | ||
from tg import config | ||
from {{package}} import websetup | ||
{{if database}}from {{package}} import model{{endif}} | ||
from os import getcwd | ||
{{if sqlalchemy}}import transaction{{endif}} | ||
|
||
|
||
{{if database}} | ||
def teardown_db(): | ||
{{if sqlalchemy}} | ||
model.DBSession.remove() | ||
engine = config['tg.app_globals'].sa_engine | ||
model.metadata.drop_all(engine) | ||
transaction.abort() | ||
{{elif ming}} | ||
datastore = config['tg.app_globals'].ming_datastore | ||
model.DBSession.clear() # before dropping flush is performed | ||
try: | ||
# On MIM drop all data | ||
datastore.conn.drop_all() | ||
except TypeError: # pragma: no cover | ||
# On MongoDB drop database | ||
datastore.conn.drop_database(datastore.db) | ||
{{endif}} | ||
{{endif}} | ||
|
||
|
||
@pytest.fixture(scope='function') | ||
def _app(): | ||
"""This fixture allows you to reconfigure the application configuration. | ||
Also, you can omit setup_app command""" | ||
def __app(name='main_without_authn', reconfig=None, setup_app=True): | ||
paste_config = 'config:test.ini#%s' % name | ||
app = WebTestApp(loadapp( | ||
paste_config, | ||
relative_to=getcwd(), | ||
global_conf=reconfig or {}, | ||
)) | ||
if setup_app: | ||
_config = appconfig(paste_config, relative_to=getcwd(), global_conf=reconfig or {}) | ||
websetup.setup_app(None, _config, {}) | ||
return app | ||
yield __app | ||
{{if database}}teardown_db(){{endif}} | ||
|
||
|
||
@pytest.fixture(scope='function') | ||
def app(_app): | ||
"""This fixture is the default application""" | ||
return _app() | ||
|
||
|
||
{{if auth}} | ||
@pytest.fixture() | ||
def env(): | ||
"""this is just a shorthand intended to be passed to extra_environ in webtest calls, | ||
remote_user got as parameter will go into REMOTE_USER key, | ||
other kwarguments are included in the returned dictionary""" | ||
def _environ(remote_user, **kwargs): | ||
r = {'REMOTE_USER': remote_user} if remote_user else {} | ||
r.update(kwargs) | ||
return r | ||
return _environ | ||
{{endif}} |
21 changes: 21 additions & 0 deletions
21
devtools/gearbox/quickstart/template/+package+/tests/_conftest/models.py_tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import pytest | ||
from {{package}}.model import DBSession | ||
from {{package}}.tests._conftest.app import teardown_db | ||
|
||
|
||
@pytest.fixture() | ||
def obj(): | ||
def _obj(klass, attrs): | ||
new_attrs = {} | ||
new_attrs.update(attrs) | ||
created = klass(**new_attrs) | ||
{{if sqlalchemy}} | ||
DBSession.add(created) | ||
DBSession.flush() | ||
{{elif ming}} | ||
created.__mongometa__.session.flush() | ||
created.__mongometa__.session.clear() | ||
{{endif}} | ||
return created | ||
yield _obj | ||
teardown_db() |
6 changes: 6 additions & 0 deletions
6
devtools/gearbox/quickstart/template/+package+/tests/conftest.py_tmpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{{if database}}from {{package}}.tests._conftest.models import obj{{endif}} | ||
from {{package}}.tests._conftest.app import app, _app{{if auth}}, env{{endif}} | ||
|
||
# Fixtures defined in _conftest came from turbogears2, change them if you wish | ||
|
||
# Place here your own fixtures. |
2 changes: 0 additions & 2 deletions
2
devtools/gearbox/quickstart/template/+package+/tests/functional/__init__.py_tmpl
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.