ImportError: cannot import name signals

2024/10/1 9:42:20

I'm using Django 1.3.0 with Python 2.7.1. In every test I write the following imports I get the importError above:

from django.utils import unittest
from django.test.client import Client

The full stack trace:

File "C:\Program Files (x86)\j2ee\plugins\org.python.pydev.debug_1.6.3.2010100513\pysrc\runfiles.py", line 342, in __get_module_from_strmod = __import__(modname)File "C:/Users/benjamin/workspace/BookIt/src/BookIt/tests\basic_flow.py", line 11, in from django.test.client import ClientFile "C:\Python27\lib\site-packages\django\test\__init__.py", line 5, in from django.test.client import Client, RequestFactoryFile "C:\Python27\lib\site-packages\django\test\client.py", line 21, in from django.test import signals
ImportError: cannot import name signals
ERROR: Module: basic_flow could not be imported.

Any ideas why this happening ?

Answer

@Hugo was right in that it was a settings.py problem. But I didn't had that problem when running through the Django environment. But when I wanted to run unit tests one by one (By using Pydev's run as unittest) it failed to run. What I needed to do was to add the Django settings module information, so for now what I'm doing is adding the following lines to my unit tests:

from django.core import management;
import BookIt.settings as settings;
management.setup_environ(settings)

This loads my Django project settings and allow me to run as regular unittest. If anyone has better suggestion on how to configure this more cleanly in Pydev please let me know.

https://en.xdnf.cn/q/70976.html

Related Q&A

Return a Pandas DataFrame as a data_table from a callback with Plotly Dash for Python

I would like to read a .csv file and return a groupby function as a callback to be displayed as a simple data table with "dash_table" library. @Lawliets helpful answer shows how to do that wi…

Nose: How to skip tests by default?

I am using Pythons nose and I have marked some of my tests as "slow", as explained in the attrib plugin documentation.I would like to skip all "slow" Tests by default when running n…

SQLAlchemy ORM select multiple entities from subquery

I need to query multiple entities, something like session.query(Entity1, Entity2), only from a subquery rather than directly from the tables. The docs have something about selecting one entity from a s…

How to ensure data is received between commands

Im using Paramiko to issue a number of commands and collect results for further analysis. Every once in a while the results from the first command are note fully returned in time and end up in the out…

Format Excel Column header for better visibility and Color

I have gone through many posts but did not found the exact way to do the below. Sorry for attaching screenshot(Just for better visibility) as well , I will write it also. Basically it looks like -Name…

Using multiple keywords in xattr via _kMDItemUserTags or kMDItemOMUserTags

While reorganizing my images, in anticipation of OSX Mavericks I am writing a script to insert tags into the xattr fields of my image files, so I can search them with Spotlight. (I am also editing the …

JAX Apply function only on slice of array under jit

I am using JAX, and I want to perform an operation like @jax.jit def fun(x, index):x[:index] = other_fun(x[:index])return xThis cannot be performed under jit. Is there a way of doing this with jax.ops …

Using my own corpus for category classification in Python NLTK

Im a NTLK/Python beginner and managed to load my own corpus using CategorizedPlaintextCorpusReader but how do I actually train and use the data for classification of text?>>> from nltk.corpus…

Python ImportError for strptime in spyder for windows 7

I cant for the life of me figure out what is causing this very odd error.I am running a script in python 2.7 in the spyder IDE for windows 7. It uses datetime.datetime.strptime at one point. I can run …

How to show diff of two string sequences in colors?

Im trying to find a Python way to diff strings. I know about difflib but I havent been able to find an inline mode that does something similar to what this JS library does (insertions in green, deletio…