数据库错误:ORA00942:表或视图不存在

2024-04-20 08:52:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我在做样本测试时遇到了问题。在

import unittest
from automation.models import Accountproperty

class TestEx(unittest.TestCase):

   def test_get_data_from_database(self):
       Accountproperty.objects.count()

if __name__ == "__main__":
unittest.main()

当我从shell运行这个测试时,我没有问题:

^{pr2}$

但当我以这种方式运行测试时,我遇到了以下问题:

C:\Users\apodar\PycharmProjects\autoTest>python manage.py test 
interface.tests.testEx.TestEx

Creating test database for alias 'default'...
Creating test user...
System check identified no issues (0 silenced).
E
======================================================================
ERROR: test_get_data_from_database (interface.tests.testEx.TestEx)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\apodar\PycharmProjects\autoTest\interface\tests\testEx.py", 
line 7, in test_get_data_from_database

   Accountproperty.objects.count()
    File "C:\Python27\lib\site-packages\django\db\models\manager.py", line 
   85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
 File "C:\Python27\lib\site-packages\django\db\models\query.py", line 364, 
in count
return self.query.get_count(using=self.db)
 File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 
499, in get_count
  number = obj.get_aggregation(using, ['__count'])['__count']
 File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 
480, in get_aggregation
    result = compiler.execute_sql(SINGLE)
 File "C:\Python27\lib\site-packages\django\db\models\sql\compiler.py", line 
894, in execute_sql
   raise original_exception
DatabaseError: ORA-00942: table or view does not exist


 ----------------------------------------------------------------------
 Ran 1 test in 0.119s

 FAILED (errors=1)
 Destroying test database for alias 'default'...
 Destroying test user...
 Destroying test database tables...

C:\Users\apodar\PycharmProjects\autoTest>

请查找管理.py公司名称:

#!/usr/bin/env python
import os
import sys
import django

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "autoTest.settings")
    django.setup()
    try:
        from django.core.management import execute_from_command_line
    except ImportError:
        # The above import may fail for some other reason. Ensure that the
        # issue is really that Django is missing to avoid masking other
        # exceptions on Python 2.
        try:
            import django
        except ImportError:
            raise ImportError(
                "Couldn't import Django. Are you sure it's installed and "
                "available on your PYTHONPATH environment variable? Did you "
                "forget to activate a virtual environment?"
            )
        raise
    execute_from_command_line(sys.argv)

在设置.py公司名称:

"""
Django settings for autoTest project.

Generated by 'django-admin startproject' using Django 1.11.3.

For more information on this file, see
https://docs.djangoproject.com/en/1.11/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.11/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

os.sys.path.append(BASE_DIR)


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.11/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '&v7fm&l%y!7*&=7#!@-as03xy0ux*%7m8$=s&hj)m+6dgbqli('

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'automation',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'autoTest.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        'debug': DEBUG,
        },
    },
]

WSGI_APPLICATION = 'autoTest.wsgi.application'


# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.oracle',
        'NAME': 'paymo33',
        'USER': 'PAYMOBILE34',
        'PASSWORD': 'PAYMOBILE34',
        'HOST': '10.33.22.48',
        'PORT': '1521',
    }
}


# Password validation
# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/1.11/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.11/howto/static-files/

STATIC_URL = '/static/'

附加信息: 我使用PyCharm作为IDE,Django 1.11.4,cx Oracle 5.2,Python 2.7.5,selenium 2.42.0

我的范围是用selenium创建python测试,它还使用数据库连接(以某种方式在单元测试中引导应用程序)

如果有必要,请告诉我更多信息。请帮忙。非常感谢。在


Tags: djangoinfrompytestimportauthget
1条回答
网友
1楼 · 发布于 2024-04-20 08:52:09

在执行SQL语句之前,不要忘记使用ALTER SESSION SET CURRENT_SCHEMA

相关问题 更多 >