Tanks for your reply. I'm not in a production environnement. I'm using web2py with students as teaching tools.
In fact, my database is sqlite. I'm running 2.12-3 version of web2py on a linux machine. Python version is 2.7.10. 2016-02-10 21:46 GMT+01:00 Dave S <snidely....@gmail.com>: > > > On Wednesday, February 10, 2016 at 11:53:27 AM UTC-8, Maelle Taurand wrote: >> >> >> Hy, >> >> I want to make unit test with web2py. >> >> I follow this page : >> https://pythonhosted.org/web2py_utils/test_runner.html. >> >> Is Web2py Test Runner always a good way for unittesting ? >> >> >> After running execute_tests.py, i have got thie result and an error >> (logged in report file) >> >> > Is your database using sqlite? (That's the "out of the box" web2py > configuration, but locking issues vs concurrency make it less desirable as > a production database).. You should also tell us what version of web2py, > what python version, and what OS. If you're running on one of the Windows > OS platforms, then your python version may be the one bundled with web2py. > > /dps > > > >> >> >> >> >> >> >> >> >> *Result : self.assertEquals(self.nbP+1, >> len(self.db().select(self.db.person.id)))AssertionError: 2 != 1*It seems >> the insert was not performed ? >> >> >> ERROR: test_ajoutPerson (web2py_utils.test_runner.TestAjoutPerson) >> ---------------------------------------------------------------------- >> Traceback (most recent call last): >> File "xxxxxx/web2py/applications/app1/tests/manage.py", line 28, in >> test_ajoutPerson >> res = self.env['ajoutPerson']("titi") >> File "xxxxxx/web2py/applications/app1/controllers/manage.py", line 24, >> in ajoutPerson >> db.person.insert(name=name) >> File "xxxxxx/web2py/gluon/packages/dal/pydal/objects.py", line 712, in >> insert >> ret = self._db._adapter.insert(self, self._listify(fields)) >> File "xxxxxxweb2py/gluon/packages/dal/pydal/adapters/base.py", line >> 739, in insert >> raise e >> OperationalError: database is locked >> >> >> >> >> Thanks for help, >> >> >> Here is the controller's function i want to test. >> >> ****************************************************************************************** >> controller : manage.py >> >> def formAjoutPerson(): >> form=SQLFORM(db.person) # person is a table that contains one field >> named 'name' >> >> if form.validate(): >> >> name=form.vars.name >> >> mess=ajoutPerson(name) >> response.flash = mess >> >> elif form.errors : >> response.flash='error in the form' >> >> return locals() >> >> def ajoutPerson(name): >> >> # the libelle must be unique >> rows = db(db.person.name == name).select(db.person.id) >> >> if len(rows) == 0: >> db.person.insert(name=name) >> mess = 'new person added' >> else: >> mess = 'Error : name already exists >> return mess >> >> >> >> >> ****************************************************************************************** >> Here is the test >> >> class TestAjoutPerson(unittest.TestCase): >> >> def setUp(self): >> self.env = new_env(app='app1', controller='manage') >> self.db = copy_db(self.env, db_name='db', db_link='sqlite:memory') >> >> >> >> self.db.person.insert(name="toto") >> self.db.commit() >> >> rows=self.db().select(self.db.person.id) >> self.nbP=len(rows) >> >> # Test method >> def test_ajoutPerson(self): >> >> res = self.env['ajoutPerson']("titi") >> self.db.commit() >> self.assertEquals("new person added", res) >> >> #TEST >> self.assertEquals(self.nbP+1, len(self.db().select(self.db.person.id >> ))) >> >> >> >> suite = unittest.TestSuite() # define a group of unit tests >> suite.addTest(unittest.makeSuite(TestAjoutTest)) #add to the suite test >> class >> >> unittest.TextTestRunner(verbosity=2).run(suite) >> >> ************************************************************************************** >> > -- > Resources: > - http://web2py.com > - http://web2py.com/book (Documentation) > - http://github.com/web2py/web2py (Source code) > - https://code.google.com/p/web2py/issues/list (Report Issues) > --- > You received this message because you are subscribed to a topic in the > Google Groups "web2py-users" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/web2py/Mr2UepU4_hI/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > web2py+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.