Testing with chameleon templates fails

29 views
Skip to first unread message

silvi...@gmail.com

unread,
Dec 19, 2020, 7:10:38 PM12/19/20
to pylons-discuss
Hello,

I have the following structure (made with pcreate -t zodb)

├── CHANGES.txt
├── Data.fs
├── Data.fs.index
├── Data.fs.lock
├── Data.fs.tmp
├── MANIFEST.in
├── README.txt
├── Test.fs
├── Test.fs.index
├── Test.fs.lock
├── Test.fs.tmp
├── development.ini
├── production.ini
├── pytest.ini
├── setup.py
├── test02
│   ├── __init__.py
│   ├── models.py
│   ├── static
│   │   ├── pyramid-16x16.png
│   │   ├── pyramid.png
│   │   └── theme.css
│   ├── templates
│   │   └── mytemplate.pt
│   ├── tests.py
│   └── views.py
└── test02.egg-info
    ├── PKG-INFO
    ├── SOURCES.txt
    ├── dependency_links.txt
    ├── entry_points.txt
    ├── not-zip-safe
    ├── requires.txt
    └── top_level.txt

# test02/__init__.py

from pyramid.config import Configurator
from pyramid_zodbconn import get_connection
from .models import appmaker


def root_factory(request):
    conn = get_connection(request)
    return appmaker(conn.root())


def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """
    config = Configurator(root_factory=root_factory, settings=settings)
    settings = config.get_settings()
    settings['tm.manager_hook'] = 'pyramid_tm.explicit_manager'
    config.include('pyramid_chameleon')  # included also in .ini
    config.add_static_view('static', 'static', cache_max_age=3600)
    config.scan()
    return config.make_wsgi_app()


My test is quite simple

# test02/tests.py
import unittest

from pyramid import testing
from webtest import TestApp
from pyramid.paster import get_app


class FuncTests(unittest.TestCase):
    def setUp(self):
        app = get_app('development.ini')
        self.testApp = TestApp(app)

    def tearDown(self):
        testing.tearDown()

    def test_root(self):
        r = self.testApp.get('/')

# development.ini
[app:main]
use = egg:test02

pyramid.reload_templates = true
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.default_locale_name = en
pyramid.includes =
    pyramid_debugtoolbar
    pyramid_zodbconn
    pyramid_tm
    pyramid_chameleon

The view works fine but fails in testing.

# test02/views.py
from pyramid.view import view_config
from .models import MyModel


@view_config(context=MyModel, renderer='templates/mytemplate.pt')
def my_view(request):
    return {'project': 'test02'}


However if I run pytest test02/tests.py I get this error

self = <pkg_resources.NullProvider object at 0x7f4aae5660a0>, path = '/home/silviud/PROGS/test02/test02/templates/mytemplate.pt'

    def _has(self, path):
>       raise NotImplementedError(
            "Can't perform this operation for unregistered loader type"
        )
E       NotImplementedError: Can't perform this operation for unregistered loader type

../../Envs/test01/lib/python3.8/site-packages/pkg_resources/__init__.py:1472: NotImplementedError


Not sure what is wrong ... these are the versions I use

pip show pkg_resources
Name: pkg-resources
Version: 0.0.0
Summary: UNKNOWN
Home-page: UNKNOWN
Author: UNKNOWN
Author-email: UNKNOWN
License: UNKNOWN
Location: /home/silviud/Envs/test01/lib/python3.8/site-packages
Requires:
Required-by:
--
pip show pyramid
Name: pyramid
Version: 1.10.5
Summary: The Pyramid Web Framework, a Pylons project
Author: Chris McDonough, Agendaless Consulting
License: BSD-derived (Repoze)
Location: /home/silviud/Envs/test01/lib/python3.8/site-packages
Requires: plaster-pastedeploy, venusian, zope.interface, plaster, hupper, webob, translationstring, zope.deprecation, setuptools
Required-by: test01, pyramid-zodbconn, pyramid-tm, pyramid-mako, pyramid-jinja2, pyramid-debugtoolbar, pyramid-chameleon, test02
--
pip show pyramid_chameleon
Name: pyramid-chameleon
Version: 0.3
Summary: pyramid_chameleon
Author: re...@koansys.com, Pylons & Pyramid community
License: BSD-derived (http://www.repoze.org/LICENSE.txt)
Location: /home/silviud/Envs/test01/lib/python3.8/site-packages
Requires: Chameleon, pyramid
Required-by: test02


thank you,

-silviu

Steve Piercy

unread,
Dec 19, 2020, 10:02:57 PM12/19/20
to pylons-...@googlegroups.com
I don't know why you have this issue. However, the scaffolds generated from pcreate have been deprecated since Pyramid 1.8 and will be removed in Pyramid 2.0. Instead use its replacement pyramid-cookiecutter-starter.

https://docs.pylonsproject.org/projects/pyramid/en/master/changes.html#id18
https://github.com/Pylons/pyramid-cookiecutter-starter

--steve
> --
> You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discus...@googlegroups.com <mailto:pylons-discus...@googlegroups.com>.
> To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/7785515d-b0f0-42df-9d5b-492472d70c87n%40googlegroups.com <https://groups.google.com/d/msgid/pylons-discuss/7785515d-b0f0-42df-9d5b-492472d70c87n%40googlegroups.com?utm_medium=email&utm_source=footer>.

silvi...@gmail.com

unread,
Dec 19, 2020, 10:17:59 PM12/19/20
to pylons-discuss
Hi Steve,

Thanks for your answer - I found that this happens _only_ with pytest.
Adding this to test file

if __name__ == '__main__':
    unittest.main(verbosity=2)

And run it as python test02/test.py collects the tests and its fine.

I guess it has to do with the way pytest makes the import of the package. I didn't find much yet ... testing with pdb.

- silviu

silvi...@gmail.com

unread,
Dec 20, 2020, 10:42:05 AM12/20/20
to pylons-discuss
I found the problem. The new cookiecutter template adds into pytest.ini a different pattern than the old.

 [pytest]
 testpaths = tests
-python_files = *.py
+python_files = test*.py

thanks again,

-silviu
Reply all
Reply to author
Forward
0 new messages