On Fri, 2010-12-31 at 10:49 -0800, Ira Lun wrote: > Hi everyone. I've been working through the Unit, Integration and > Functional Testing chapter in the Pyramid narrative docs, and have a > couple of questions I hope you could help me with? > > 1) Working with Mako (with mako.directories set in development.ini), > and using the code in the "Creating Functional Tests" section: > > def setUp(self): > from myapp import main > app = main({}) > from webtest import TestApp > self.testapp = TestApp(app) > > raises a "ConfigurationError: Mako template used without a > ``mako.directories`` setting". Couldn't get it to read the setting in > development.ini until I tried > > from webtest import TestApp > self.testapp = TestApp("config:development.ini", relative_to="./") > > which works -- but is this the best way? (If yes, is it worth > mentioning in the docs?) And are there any plans for a test.ini in the > future, as in Pylons, or is there a better way to do it in Pyramid?
That seems like a pretty good way to do it. I actually didn't really know it could be done that way, and is probably worth adding to the docs. You could also do, FTR: app = main({}, **{'mako.directories':['/some/dir/or/asset/spec']}) The second set of keyword args passed to main are "settings", and the 'mako.directories' setting can be one of them. Every setting Pyramid defines (http://docs.pylonshq.com/pyramid/dev/narr/environment.html) can be passed this way. > 2) Been working through the Unit Testing Guidelines from the Pylons > Project at the same time, trying to learn best practices -- but am a > bit unclear on the guideline of "Share setup via helper methods, not > via attributes of self". Does that apply to the self.testapp in the > example quoted above from "Creating Functional Tests"? Or the > self.config = Configurator(autocommit=True) setUp in unit testing, or > database sessions (self.session in the SQLAlchemy + URL Dispatch Wiki > Tutorial)? We've ignored dogma in some of those cases. The self.testapp case is excused a-priori because the test is a functional test, not a unit test. The tests with self.session in it are also mostly excused. Most tests that need SQLAlchemy are at least integration tests; there's doesn't really seem to be a good way to provide a suitable mock for a sqlalchemy session. self.config = Configurator(autocommit=True) is not excused, it's a violation of the dogma. I actually will be changing this to obey the dogma soon by modifying the paster templates to call "pyramid.testing.setUp" and "pyramid.testing.tearDown" rather than by assigning a Configurator to self and calling methods on it from testcase setUp/tearDown. I won't be changing this in order just to obey the dogma, there are other reasons for it too. In any case, the text in the testing chapter about this is big dogma. We sometimes ignore it or bend it to our needs. > What is "unneeded work in the setUp method of a testcase > class", and what would be considered "needed work"? I often violate the dogma and set attributes on the test case in setUp related to a *framework*. I almost never violate dogma to set attributes on the test case in setUp related to "domain objects". > > Thanks in advance for your help -- I hope I'll feel competent enough > to contribute to the project very soon! > > Great! - C -- You received this message because you are subscribed to the Google Groups "pylons-devel" group. To post to this group, send email to pylons-de...@googlegroups.com. To unsubscribe from this group, send email to pylons-devel+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-devel?hl=en.