我将我的test.py文件拆分成多个文件,比如
app
app\models.py
app\views.py
app\tests
app\tests__init__.py
app\tests\test_bananas.py
app\tests\test_apples.py
Run Code Online (Sandbox Code Playgroud)
和导入如下__init__.py:
from test_bananas import BananasTest
from test_apples import ApplesTest
Run Code Online (Sandbox Code Playgroud)
pyflakes给我错误
modules/app/tests/__init__.py:5: [E] PYFLAKES:'BananasTest' imported but unused
modules/app/tests/__init__.py:5: [E] PYFLAKES:'ApplesTest' imported but unused
Run Code Online (Sandbox Code Playgroud)
试过这个也
from test_bananas import *
from test_apples import *
Run Code Online (Sandbox Code Playgroud)
再次pyflakes给我错误
PYFLAKES:'from test_bananas import *' used; unable to detect undefined names
PYFLAKES:'from test_apples import *' used; unable to detect undefined names
Run Code Online (Sandbox Code Playgroud) 如何知道我点击的项目的ID?我的代码如下:
$(function() {
ipl.mvc.view.openings_view = ipl.mvc.view.view_base.extend({
template: '/assets/t/plmt/companies.tmpl.html',
ID: '#tmpl_openings',
events: {
"click #edit": "editpost"
},
initialize: function() {
var _this = this;
_.bindAll(this, 'addOne', 'addAll', 'render', 'editpost');
_this.loadTemplate(_this.template, function() {
_this.model = new ipl.mvc.model.companies_model([]);
_this.model.view = _this;
_this.model.bind('change', _this.render, _this);
});
}
,
render: function() {
var _this = this
jsonData = _this.model.toJSON();
_.each(jsonData, function(model) {
$(_this.ID).tmpl(model).appendTo(_this.el);
return _this;
});
}
,
editpost: function(e) {
console.log("EDIT CLICKED");
e.preventDefault();
var ele = $(e.target);
console.log(ele);
_this.model = new ipl.mvc.collection.companies_collection([]);
var id …Run Code Online (Sandbox Code Playgroud) 我的代码如下
class Something(models.Model)
def exception(self)
try:
Something.objects.all()
except Exception():
raise Exception()
Run Code Online (Sandbox Code Playgroud)
从testcases调用此方法,它的工作,但我需要引发异常,它不会捕获异常,这是我的测试用例
def test_exception(self):
instance = Something()
instance.exception()
Run Code Online (Sandbox Code Playgroud)
它工作正常,但我需要从块除外引发异常
我的代码如下:
def getAllVehicles(self):
try:
vehobj = Vehicles.objects.all()
except VehicleDoesNotExists, e:
logger.debug("Exception in getAllVehicles() is :::: %s ", e)
return vehobj
Run Code Online (Sandbox Code Playgroud)
这是我的测试用例:
def test_getAllVehicles(self):
Vehicles.objects.all().delete()
instance = Vehicles()
self.assertRaises(VehicleDoesNotExists, instance.getAllVehicles)
Run Code Online (Sandbox Code Playgroud)
永远不会提出异常,但我要求:
Vehicles.objects.all()
Run Code Online (Sandbox Code Playgroud)
提出例外.
代码覆盖率要求我执行except块.