On Wed, Aug 05 2015, Manlio Perillo wrote: > 2015-08-05 19:00 GMT+02:00 Marco Giusti <marco.giu...@posteo.de>: > > > On Wed, Aug 05 2015, Manlio Perillo wrote: > > > Oggi per la prima volta sto lavorando ad un progetto che contiene più di > > un > > > package: > > > > > > pkg/ > > > foo/ > > > bar/ > > > test/ > > > foo/ > > > bar/ > > > > > > La directory `test` contiene la test suite. > > > > > > Il problema è che quando eseguo i test con nosetests, l'istruzione > > > `import foo` importa il package da `pkg/test/foo` invece che `pkg/foo`. > > > > > [...] > > > > Qualcuno può confermare il problema e suggerire una soluzione? > > > > Non saprei dirti, il semplice test che ho fatto sembra funzionare. > > > > Usi Python 3 o Python 2? > Io sto usando Python 2.
Non mi ero neanche posto il problema. Python 2.7.9, nose installato con pip. > > La prima cosa che ho pensato è che nose cambiasse il path corrente e, > > per esempio, trovandosi in test/, importasse i moduli sbalgiati. > > > Lo fa. > Senza l'opzione -P aggiunge la directory che sta testando all'inizio di > sys.path. > > La cosa strana e che non capisco è che ottengo il comportamento sbagliato > anche se aggiungo l'opzione. > > > [...] $ nosetests .. ---------------------------------------------------------------------- Ran 2 tests in 0.030s OK $ nosetests test/ .. ---------------------------------------------------------------------- Ran 2 tests in 0.001s OK $ rm test/__init__.py $ nosetests .. ---------------------------------------------------------------------- Ran 2 tests in 0.008s OK $ nosetests test/ EE ====================================================================== ERROR: test.bar.test_bar.test_whoami ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/marco/.virtualenvs/test/local/lib/python2.7/site-packages/nose/case.py", line 197, in runTest self.test(*self.arg) File "/home/marco/.virtualenvs/test/src/pythonpkg/test/bar/test_bar.py", line 4, in test_whoami assert bar.whoami() == "bar.__init__" AttributeError: 'module' object has no attribute 'whoami' ====================================================================== ERROR: test.foo.test_foo.test_whoami ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/marco/.virtualenvs/test/local/lib/python2.7/site-packages/nose/case.py", line 197, in runTest self.test(*self.arg) File "/home/marco/.virtualenvs/test/src/pythonpkg/test/foo/test_foo.py", line 4, in test_whoami assert foo.whoami() == "foo.__init__" AttributeError: 'module' object has no attribute 'whoami' ---------------------------------------------------------------------- Ran 2 tests in 0.002s FAILED (errors=2) $ nosetests -P test/ .. ---------------------------------------------------------------------- Ran 2 tests in 0.001s OK Ti faccio notare che lo stesso comportamento, vista la struttura del package, lo ottengo con o senza "develop". Una cosa che prenderei in considerazione, e forse lo hai già fatto, è di mettere i test dentro i package. Trovo comodo effettuare i test anche in fase di deploying, soprattutto visto il tempo richiesto per scriverli e mantenerli. Spiacente di non essere più di aiuto. Ciao Marco _______________________________________________ Python mailing list Python@lists.python.it http://lists.python.it/mailman/listinfo/python