django test模块
今天试了试django自带的test模块,断点执行到一下代码中时发现一点儿小问题:
def _create_test_db(self, verbosity, autoclobber):
"""
Internal implementation - creates the test db tables.
"""
suffix = self.sql_table_creation_suffix() test_database_name = self._get_test_db_name() qn = self.connection.ops.quote_name # Create the test database and connect to it. We need to autocommit
# if the database supports it because PostgreSQL doesn't allow
# CREATE/DROP DATABASE statements within transactions.
cursor = self.connection.cursor()
self._prepare_for_test_db_ddl()
try:
cursor.execute(
"CREATE DATABASE %s %s" % (qn(test_database_name), suffix))
except Exception as e:
sys.stderr.write(
"Got an error creating the test database: %s\n" % e)
if not autoclobber:
confirm = input(
"Type 'yes' if you would like to try deleting the test "
"database '%s', or 'no' to cancel: " % test_database_name)
if autoclobber or confirm == 'yes':
try:
if verbosity >= 1:
print("Destroying old test database '%s'..."
% self.connection.alias)
cursor.execute(
"DROP DATABASE %s" % qn(test_database_name))
cursor.execute(
"CREATE DATABASE %s %s" % (qn(test_database_name),
suffix))
except Exception as e:
sys.stderr.write(
"Got an error recreating the test database: %s\n" % e)
sys.exit(2)
else:
print("Tests cancelled.")
sys.exit(1) return test_database_name
有问题的代码在于,confirm根本无法从dos输入获得‘yes’,因为输入后,会将换行符'\r'也读进去。因此,无论输入yes 还是cancel,都会走到线面的else分支,
print("Tests cancelled.")
sys.exit(1)
改掉代码后,正确执行,销毁旧的database,新建了test database。
django test模块的更多相关文章
- Django学习之六:Django 常用模块导入记忆
Django 常用模块导入记忆 django相关 1. urls相关操作 from django.urls import path, re_path, include from django.urls ...
- django日志,django-crontab,django邮件模块
django 日志 四大块,格式器,过滤器,处理器,日志管理器 LOGGING = { 'version': 1, 'disable_existing_loggers': True, 'formatt ...
- django 数据库连接模块解析及简单长连接改造
django 数据库连接模块解析及简单长连接改造工作中纯服务端的项目用到了线程池和django的ORM部分.django 的数据库连接在每一个线程中开启一份,并在查询完毕后自动关闭连接. 线程池处理任 ...
- $Django 发送邮件--django封装模块和python内置SMTP模块
一 使用SMTP模块发送邮件 import smtplib from email.mime.text import MIMEText from email.header import Header m ...
- Django admin模块无法调用css样式文件
在使用Django Admin开发时,发现admin模块css样式文件丢失,无法调用,使火狐浏览器提示: 此 URL 的资源不是文本: http://127.0.0.1:8000/statics/ad ...
- django ---Auth模块
Auth模块 本文目录 1 Auth模块是什么 2 auth模块常用方法 3 扩展默认的auth_user表 回到目录 1 Auth模块是什么 Auth模块是Django自带的用户认证模块: 我们在开 ...
- Python3.5 学习十九 Django分模块讲解 MTV+URL
本节内容概述: 表单提交的Method使用规则:get 获取数据 post提交数据 单选使用get 多选使用getlist request.POST.getlist("favor" ...
- Django ImportError 模块路径正确,且将文件夹设置为Source Root
问题描述: 在用PyCharm进行Django项目开发时,由于业务需求需要增加一个外键字段,但在引入外键关联的model时,报错ImportError 解决方案: 无奈中,尝试更改导入模块语句的位置, ...
- 十一、Django认证模块--Auth模块
一.常规认证方法 我们学生管理之登录实现一文中已经了解了自己写一个登录逻辑的过程: 1.url配置 urlpatterns = [ url(r'^login/$', views.login), url ...
随机推荐
- php使用正则函数使用详解
1. int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, in ...
- C#使用System.IO.Path获取文件路径、文件名
class Program { static void Main(string[] args) { //获取当前运行程序的目录 string fileDir = Environment.Current ...
- JAVA字符串怎么转换成整数
首先你要确定你的字符串可以转换为int类型的,比如说: String s = "123"; 如果String s = "abc";则转换时会报错! 需要的包是& ...
- RPC框架与分布式服务框架的区别
第一:RPC框架是点对点的通信方式,即服务消费者与服务提供者是点对点通信 第二:分布式服务框架,不近具有RPC框架的特性,同时,还包括以下特性: 1.提供多台服务器提供服务,具有负载均衡策略 2.服务 ...
- [转].Net连接池超时注意事项
http://blog.csdn.net/jxqvip/article/details/6738551 超时时间已到.超时时间已到,但是尚未从池中获取连接.出现这种情况可能是因为所有池连接均在使用,并 ...
- centos5中添加163yum源
1.我们用linux系统的时候,经常需要使用yum.但是如果使用系统自带的yum源时,往往速度很慢,而且经常容易出错.其实国内有很多优秀的开源的yum源.比如(163,sohu,中科大).这里我以16 ...
- LeetCode之Decode Ways
A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' - ...
- Ubuntu上CUDA环境搭建
1.下载CUDA:https://developer.nvidia.com/cuda-toolkit-archive (如果已经安装了N卡驱动,最好用.deb,如果没有安装,可以用.run) 2.根据 ...
- Linux之统计特定进程运行数量
比如统计用户名为albert运行python的进程数目 ps -u albert | grep -c "python"
- 打开应用中SQLite文件的方法
1.先找到sdk中的platform-tools文件夹下的adb.exe 2.打开dos命令窗口依次输入 :adb shell → sqlite3 /data/data/com.example.s ...