Testing Django in a Virtual Environment - django

I have a Django project setup under virtualenv, and have a empty tests.py under the project folder.
When I do "python manage.py test", I am getting the following error:
Traceback (most recent call last):
File "manage.py", line 12, in <module>
execute_from_command_line(sys.argv)
File "/Users/dj_prj/dj_prj/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/Users/dj_prj/dj_prj/env/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/dj_prj/dj_prj/env/lib/python2.7/site-packages/django/core/management/commands/test.py", line 50, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/Users/dj_prj/dj_prj/env/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/dj_prj/dj_prj/env/lib/python2.7/site-packages/django/core/management/commands/test.py", line 71, in execute
super(Command, self).execute(*args, **options)
File "/Users/dj_prj/dj_prj/env/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/Users/dj_prj/dj_prj/env/lib/python2.7/site-packages/django/core/management/commands/test.py", line 88, in handle
failures = test_runner.run_tests(test_labels)
File "/Users/dj_prj/dj_prj/oicms/test/oicms_test_runner.py", line 209, in run_tests
suite = self.build_suite(test_labels, extra_tests)
File "/Users/dj_prj/dj_prj/oicms/test/oicms_test_runner.py", line 150, in build_suite
tests = self.test_loader.discover(start_dir=label, **kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/loader.py", line 206, in discover
tests = list(self._find_tests(start_dir, pattern))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/loader.py", line 267, in _find_tests
raise ImportError(msg % (mod_name, module_dir, expected_dir))
ImportError: 'tests' module incorrectly imported from '/Users/dj_prj/dj_prj/dj_prj'. Expected '/Users/dj_prj/dj_prj/'. Is this module globally installed?

What is your environment?
Your problem may be related to this one:
Django test runner fails in virtualenv on Ubuntu

Related

Having problem with Django application using Pycharm Professional

I started a django project yesterday using pyCharm professional as text editor. Very thing was working well before I shoutdown my system. But after I restart my system, I started getting this error.
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm 2020.1.3\plugins\python\helpers\pycharm\django_manage.py", line 59, in <module>
run_command()
File "C:\Program Files\JetBrains\PyCharm 2020.1.3\plugins\python\helpers\pycharm\django_manage.py", line 46, in run_command
run_module(manage_file, None, '__main__', True)
File "C:\Users\OBUM\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 207, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "C:\Users\OBUM\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "C:\Users\OBUM\AppData\Local\Programs\Python\Python38\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:/Users/OBUM/PycharmProjects/newproject\manage.py", line 21, in <module>
main()
File "C:/Users/OBUM/PycharmProjects/newproject\manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\OBUM\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\OBUM\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\OBUM\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\OBUM\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\commands\runserver.py", line 60, in execute
super().execute(*args, **options)
File "C:\Users\OBUM\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\base.py", line 364, in execute
output = self.handle(*args, **options)
File "C:\Users\OBUM\AppData\Local\Programs\Python\Python38\lib\site-packages\django\core\management\commands\runserver.py", line 67, in handle
if not settings.DEBUG and not settings.ALLOWED_HOSTS:
File "C:\Users\OBUM\AppData\Local\Programs\Python\Python38\lib\site-packages\django\conf\__init__.py", line 79, in __getattr__
self._setup(name)
File "C:\Users\OBUM\AppData\Local\Programs\Python\Python38\lib\site-packages\django\conf\__init__.py", line 60, in _setup
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Requested setting DEBUG, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
Can someone help me please
that will happen sometimes when your trying to run your app with 'run' icon (green triangle).
try this command in the terminal :
python manage.py runserver

API Test Case - 'module' object has no attribute

$ python manage.py test homepage.shortlistedlist
When i run above django rest framework testcase file, i met below error, kindly help me to solve this problem,
(py3.4)testuser#testuser-To:~/projects/testfile/testfile$ python manage.py test homepage.compareproperties --settings=testfile.settings.test
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/core/management/commands/test.py", line 50, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/core/management/commands/test.py", line 71, in execute
super(Command, self).execute(*args, **options)
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/core/management/commands/test.py", line 88, in handle
failures = test_runner.run_tests(test_labels)
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/test/runner.py", line 146, in run_tests
suite = self.build_suite(test_labels, extra_tests)
File "/home/testuser/envs/testfile/lib/python3.4/site-packages/django/test/runner.py", line 95, in build_suite
tests = self.test_loader.discover(start_dir=label, **kwargs)
File "/usr/lib/python3.4/unittest/loader.py", line 255, in discover
self._get_directory_containing_module(top_part)
File "/usr/lib/python3.4/unittest/loader.py", line 269, in _get_directory_containing_module
full_path = os.path.abspath(module.__file__)
AttributeError: 'module' object has no attribute '__file__'
Thanks In Advance,
I was able to solve this by adding an empty __init__.py to the root of my project.
I think the clue is the get_directory_containing_module() call - without __init__.py, it doesn't see the directory as a module.

South not migrating taggit.managers

I just added tags=TaggableManager() in my models.py file. And i initiated to run python manage.py schemamigration myapp --initial it shows below error
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python2.7/dist-packages/South-0.8.1-py2.7.egg/south/management/commands/schemamigration.py", line 151, in handle
for action_name, params in change_source.get_changes():
File "/usr/local/lib/python2.7/dist-packages/South-0.8.1-py2.7.egg/south/creator/changes.py", line 460, in get_changes
model_defs = freeze_apps([self.migrations.app_label()])
File "/usr/local/lib/python2.7/dist-packages/South-0.8.1-py2.7.egg/south/creator/freezer.py", line 32, in freeze_apps
frozen_models.update(model_dependencies(model))
File "/usr/local/lib/python2.7/dist-packages/South-0.8.1-py2.7.egg/south/creator/freezer.py", line 96, in model_dependencies
depends.update(field_dependencies(field, checked_models))
File "/usr/local/lib/python2.7/dist-packages/South-0.8.1-py2.7.egg/south/creator/freezer.py", line 132, in field_dependencies
value = get_attribute(field, attrname)
File "/usr/local/lib/python2.7/dist-packages/South-0.8.1-py2.7.egg/south/utils/__init__.py", line 38, in get_attribute
value = getattr(value, part)
AttributeError: 'TaggableManager' object has no attribute 'primary_key'
In south migration tutorials itself they said to add below two lines. I did
from south.modelsinspector import add_ignored_fields
add_ignored_fields(["^taggit\.managers"])
Nothing happened. But the same error coming again

Why do I get this error when I run "python manage.py syncdb --all"?

I am trying to apply tutorial http://docs.django-cms.org/en/2.1.3/getting_started/tutorial.html.
But I didn't succeed to perform the initial database setup
Why do I get this error when I run "python manage.py syncdb --all" ?
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 442, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 381, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 195, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 230, in execute
self.validate()
File "C:\Python27\lib\site-packages\django\core\management\base.py", line 266, in validate
num_errors = get_validation_errors(s, app)
File "C:\Python27\lib\site-packages\django\core\management\validation.py", line 30, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "C:\Python27\lib\site-packages\django\db\models\loading.py", line 158, in get_app_errors
self._populate()
File "C:\Python27\lib\site-packages\django\db\models\loading.py", line 64, in _populate
self.load_app(app_name, True)
File "C:\Python27\lib\site-packages\django\db\models\loading.py", line 88, in load_app
models = import_module('.models', app_name)
File "C:\Python27\lib\site-packages\django\utils\importlib.py", line 35, in import_module
__import__(name)
File "C:\Python27\lib\site-packages\django_cms-2.2-py2.7.egg\cms\plugins\link\models.py", line 5, in <module>
class Link(CMSPlugin):
File "C:\Python27\lib\site-packages\django_cms-2.2-py2.7.egg\cms\plugins\link\models.py", line 11, in Link
url = models.URLField(_("link"), verify_exists=False, blank=True, null=True)
File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py", line 1265, in __init__
CharField.__init__(self, verbose_name, name, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py", line 614, in __init__
super(CharField, self).__init__(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'verify_exists'
The verify_exists parameter for UrlField was deprecated in the 1.3.1 security release and removed in the current Git master (1.5dev). https://docs.djangoproject.com/en/1.4/internals/deprecation/. This makes this version of django-cms incompatible with the current master. I would recommend using a stable Django release such as the latest 1.4 rather than master.

Django-jython war file deployment

Trying to create a war file from my django program, keep running into this error when running jython manage.py war:
jython manage.py war --include-java-libs "/home/user/Downloads/mysql-connector-java-5.1.18/mysql-connector-java-5.1.18-bin.jar"
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 219, in execute
self.validate()
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 219, in execute
self.validate()
File "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
File "/usr/lib/python2.7/site-packages/django/core/management/validation.py", line 28, in get_validation_errors
from django.db import models, connection
File "/usr/lib/python2.7/site-packages/django/db/__init__.py", line 78, in <module>
connection = connections[DEFAULT_DB_ALIAS]
File "/usr/lib/python2.7/site-packages/django/db/utils.py", line 94, in __getitem__
conn = backend.DatabaseWrapper(db, alias)
File "/usr/lib/python2.7/site-packages/doj/backends/zxjdbc/mysql/base.py", line 152, in __init__
self.features = DatabaseFeatures()
TypeError: __init__() takes exactly 2 arguments (1 given)
Any help would be greatly appreciated!
Appears to be a known bug, hopefully taken care of soon.
http://code.google.com/p/django-jython/issues/detail?id=56&q=mysql