迁移期间Selenium django错误

时间:2016-03-17 17:13:01

标签: python django selenium django-hstore

我正在尝试使用selenium来测试我的django应用程序

运行以下命令后:

python3 manage.py test function_test(folder)

出现以下错误:

*Traceback (most recent call last):
  File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", line 130, in ensure_connection
    self.connect()
  File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/base.py", line 122, in connect
    connection_created.send(sender=self.__class__, connection=self)
  File "/usr/local/lib/python3.4/dist-packages/django/dispatch/dispatcher.py", line 189, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/usr/local/lib/python3.4/dist-packages/django_hstore/apps.py", line 48, in __call__
    return [x(connection) for x in handlers]
  File "/usr/local/lib/python3.4/dist-packages/django_hstore/apps.py", line 48, in <listcomp>
    return [x(connection) for x in handlers]
  File "/usr/local/lib/python3.4/dist-packages/django_hstore/apps.py", line 76, in register_hstore_handler
    register_hstore(connection.connection, globally=HSTORE_REGISTER_GLOBALLY)
  File "/usr/local/lib/python3.4/dist-packages/psycopg2/extras.py", line 775, in register_hstore
    "hstore type not found in the database. "
psycopg2.ProgrammingError: hstore type not found in the database. please install it from your 'contrib/hstore.sql' fil*e

我已经在我的主项目中安装了hstore,并且我在live_server_test_case上运行了测试,因此它不会产生问题。

有没有办法可以在运行selenium代码之前跳过迁移,因为我已经提到在setup()函数中创建了hstore类型,但是我无法访问代码。

1 个答案:

答案 0 :(得分:0)

当您运行测试时,Django会创建一个测试数据库。使用public static class Dissplay extends JPanel{ /** * */ private static final long serialVersionUID = 1L; public void paintComponent(Graphics g){ super.paintComponent(g); g.drawString("Please enter you plugin folder location and what you want to install.", 30, 20); } } static JTextField input; static JCheckBox villagesBox; static JCheckBox slabsBox; static JFrame window; static boolean clicked; public static void main(String[] args) { clicked = false; input = new JTextField("Enter plugin folder location here"); input.addMouseListener(new MouseAdapter(){ public void mouseClicked(MouseEvent e){ if(clicked){ } else { input.setText(""); clicked = true; } } }); JPanel content1 = new JPanel(); JPanel content2 = new JPanel(); JPanel content3 = new JPanel(); content3.setLayout(new BorderLayout()); content1.setLayout(new BorderLayout()); content2.setLayout(new GridLayout(0,2)); content3.add(input, BorderLayout.SOUTH); content3.add(new Dissplay(), BorderLayout.CENTER); villagesBox = new JCheckBox("Villages"); content1.add(content3, BorderLayout.NORTH); villagesBox.setSelected(false); slabsBox = new JCheckBox("Slabs"); slabsBox.setSelected(false); content2.add(villagesBox); content2.add(slabsBox); JButton button = new JButton("Go"); ActionListener buttonLisener = new Button(); button.addActionListener(buttonLisener); content1.add(button, BorderLayout.SOUTH); window = new JFrame(); window.setContentPane(content1); window.add(content2, 0); window.setSize(200, 150); window.setLocation(100, 100); window.setVisible(true); } 意味着测试可以使用Django服务器(例如Selenium),它并不意味着它使用实时数据库。

听起来您需要创建迁移才能安装HStoreExtension。 Django测试运行器将运行迁移,以防止错误。有关详细信息,请参阅the docsthis question