कॉल किया गया जब मैं अपने परीक्षण चलाता हूं जिसमें @classmethod
को सेटअपटॉल्स और नाक 2 का उपयोग करके कॉल करना शामिल है, तो परीक्षण सूट समाप्त नहीं होता है, यह केवल चल रहा है। हालांकि मैंने जांच की है कि परीक्षण वास्तव में कार्य के अंत तक पहुंचता है और पहुंचता है, परीक्षण सूट बस खत्म नहीं होता है। यदि मैं decode_auth_token
का उपयोग कर परीक्षण हटा देता हूं तो यह ठीक काम करता है। मैं कक्षा के तरीकों से इसे संकीर्ण करने में सक्षम था क्योंकि मैंने अन्य वर्ग विधियों का भी परीक्षण किया था और वे एक ही समस्या का कारण बनते हैंपायथन नाक 2 टेस्ट समाप्त नहीं होने पर क्लास विधि
क्या किसी को पता है कि यह क्यों हो रहा है? नीचे मेरी कोड
संहिता की बहुत ज्यादा मेरे उपयोगकर्ता में निम्न दो कार्य भी समस्या पोस्टिंग मॉडल
@classmethod
def decode_auth_token(cls, auth_token):
try:
payload = jwt.decode(auth_token, config.SECRET_KEY, algorithms=['HS256'])
# check the hash of what we expect the token to be and token we got to be the same
if bcrypt.check_password_hash(User.by_id(payload['sub']).api_token_hash, auth_token):
return payload['sub']
else:
return 'Token does not match Api Token.'
except jwt.ExpiredSignatureError:
return 'Signature expired. Please log in again.'
except jwt.InvalidTokenError:
return 'Invalid Token. Please log in again.'
कारण जब कहा जाता
@classmethod
def is_username_taken(cls, username):
return db.session.query(db.exists().where(User.username==username)).scalar()
@classmethod
def is_email_taken(cls, email):
return db.session.query(db.exists().where(User.email==email)).scalar()
इस समारोह करता है बिना कोड के प्रासंगिक टुकड़े कर रहे हैं
@classmethod
def by_username(cls, username):
return User.query.filter(User.username == username).first()
यहां समस्या का कारण नहीं है परीक्षण
import unittest
import sys
from . import AppTestCase, API_ROOT
from app.extensions import db, bcrypt
from app.models import User, UserSchema, Location, Company
class TestUserModel(AppTestCase):
def test_encode_auth_token(self):
user = User.by_username('jdoe')
auth_token = user.encode_auth_token(user.id)
self.assertTrue(isinstance(auth_token, bytes))
def test_decode_auth_token(self):
user = User.by_username('jdoe')
auth_token = user.encode_auth_token(user.id)
self.assertTrue(isinstance(auth_token, bytes))
self.assertEqual(User.decode_auth_token(auth_token), user.id)
print('DONE')
पहला परीक्षण ठीक काम करता है, दूसरे टेस्ट प्रिंट बाहर Done
और ठीक से उचित प्रयोक्ता आईडी लौटने auth_token डीकोड लेकिन टेस्ट स्वीट समाप्त करने के लिए कारण नहीं है। यह सिर्फ प्रिंटिंग के बाद चल रहा है।
और यहाँ, सेटअप स्क्रिप्ट है मैं python setup.py test
import os
from setuptools import setup, find_packages, Command
# Thanks http://stackoverflow.com/questions/3779915/why-does-python-setup-py-sdist-create-unwanted-project-egg-info-in-project-r
class CleanCommand(Command):
"""Custom clean command to tidy up the project root."""
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
os.system('rm -vrf ./build ./dist ./*.pyc ./*.tgz ./*.egg-info')
with open('requirements.txt') as f:
requirements = f.read().splitlines()
setup(
name="XXX",
description="XXX",
version=1.0,
packages=find_packages(),
install_requires=requirements,
include_package_data=True,
test_suite='nose2.collector.collector',
tests_require=['nose2'],
cmdclass={
'clean': CleanCommand,
}
)
आउटपुट का उपयोग करते समय चल रहा है और रोक नहीं
running test
Searching for nose2
Best match: nose2 0.6.5
Processing nose2-0.6.5-py3.6.egg
Using XXX/.eggs/nose2-0.6.5-py3.6.egg
running egg_info
writing doomfist.egg-info/PKG-INFO
writing dependency_links to XXX.egg-info/dependency_links.txt
writing requirements to XXX.egg-info/requires.txt
writing top-level names to XXX.egg-info/top_level.txt
reading manifest file 'XXX.egg-info/SOURCES.txt'
writing manifest file 'XXX.egg-info/SOURCES.txt'
running build_ext
/Users/XXX/anaconda3/envs/XXX/lib/python3.6/site-packages/python_dateutil-2.6.0-py3.6.egg/dateutil/parser.py:50: DeprecationWarning: invalid escape sequence \.
/Users/XXX/anaconda3/envs/XXX/lib/python3.6/site-packages/python_dateutil-2.6.0-py3.6.egg/dateutil/parser.py:50: DeprecationWarning: invalid escape sequence \.
/Users/XXX/anaconda3/envs/XXX/lib/python3.6/site-packages/python_dateutil-2.6.0-py3.6.egg/dateutil/tz/win.py:197: DeprecationWarning: invalid escape sequence \{
/Users/XXX/anaconda3/envs/XXX/lib/python3.6/site-packages/python_dateutil-2.6.0-py3.6.egg/dateutil/tz/win.py:247: DeprecationWarning: invalid escape sequence \{
/Users/XXX/anaconda3/envs/XXX/lib/python3.6/site-packages/python_dateutil-2.6.0-py3.6.egg/dateutil/tz/win.py:197: DeprecationWarning: invalid escape sequence \{
/Users/XXX/anaconda3/envs/XXX/lib/python3.6/site-packages/python_dateutil-2.6.0-py3.6.egg/dateutil/tz/win.py:247: DeprecationWarning: invalid escape sequence \{
NOT running in debug mode
DONE
^]^\[1] 35752 quit python setup.py test
संपादित परीक्षण चलाने ----- विशाल पद अब के लिए खेद है टिप्पणियों में किसी की सलाह के साथ मैंने यह निर्धारित करने के लिए एक डीबगर का उपयोग किया कि यह वास्तव में परीक्षण समाप्त करता है। और जहां यह वास्तव में अटक गया है आंसूडाउन() के दौरान है। मेरा निम्नलिखित कार्य है जहां यह अटक जाता है।
def tearDown(self):
"""Clean db session and drop all tables."""
db.drop_all()
डिबगर के बाद आगे नीचे मैं निर्धारित यह अंततः इस विधि self.traverse_single(table, drop_ok=True, _is_metadata_operation=True)
पर विशेष रूप से
for table, fkcs in collection:
if table is not None:
self.traverse_single(table, drop_ok=True, _is_metadata_operation=True)
else:
for fkc in fkcs:
...
अटक जाती है। मुझे लगता है कि जेनरेटर लौटने के लिए इंतजार कर रहा है? असुरक्षित लेकिन नीचे की आखिरी पंक्तियां मुझे फिर से अटकने से पहले मिल गईं।
> /Users/XXX/anaconda3/envs/XXX/lib/python3.6/site-packages/SQLAlchemy-1.1.11-py3.6-macosx-10.7-x86_64.egg/sqlalchemy/sql/ddl.py(929)visit_table()->None
-> _is_metadata_operation=_is_metadata_operation)
(Pdb) n
--Call--
> /Users/XXX/anaconda3/envs/XXX/lib/python3.6/site-packages/SQLAlchemy-1.1.11-py3.6-macosx-10.7-x86_64.egg/sqlalchemy/sql/visitors.py(150)_visitor_iterator()-><sqlalchemy.s...t 0x112045630>
-> yield v
(Pdb) n
GeneratorExit
> /Users/XXX/anaconda3/envs/XXX/lib/python3.6/site-packages/SQLAlchemy-1.1.11-py3.6-macosx-10.7-x86_64.egg/sqlalchemy/sql/visitors.py(150)_visitor_iterator()-><sqlalchemy.s...t 0x112045630>
-> yield v
(Pdb) l
145 def _visitor_iterator(self):
146 """iterate through this visitor and each 'chained' visitor."""
147
148 v = self
149 while v:
150 -> yield v
151 v = getattr(v, '_next', None)
152
153 def chain(self, visitor):
154 """'chain' an additional ClauseVisitor onto this ClauseVisitor.
155
(Pdb) n
मेरा मानना है कि यह मेरा निम्न तालिका पर अटक जाती है
from ..helpers import get_current_time
from ..extensions import db, ma
from ..constants import STRING_LEN, DESCRIPTION_LEN
from .worker import WorkerSchema
class Injury(db.Model):
__tablename__ = "injuries"
def __repr__(self):
return '<Injury %r>' % (self.id)
id = db.Column(db.Integer, primary_key = True)
title = db.Column(db.String(STRING_LEN), nullable=False)
description = db.Column(db.String(DESCRIPTION_LEN), nullable=False)
worker_id = db.Column(db.Integer, db.ForeignKey('workers.id'))
created_at = db.Column(db.DateTime, nullable=False, default = get_current_time)
updated_at = db.Column(db.DateTime, nullable=False, default = get_current_time, onupdate=get_current_time)
# Relationships
worker = db.relationship('Worker', back_populates='injuries')
# ================================================================
# ================================================================
# methods
# ================================================================
# Class methods
@classmethod
def by_id(cls, id):
return cls.query.filter(Injury.id==id).first()
class InjurySchema(ma.Schema):
class Meta:
fields = ('id', 'title', 'description', 'worker')
worker = ma.Nested(WorkerSchema)
जब आप टेस्ट सूट की समस्या का सामना नहीं करते हैं, तो क्या नाक आपको बताता है कि यह वर्तमान में चल रहा है _which_ फ़ंक्शन? यदि हां, तो क्या आप आउटपुट को शामिल करने के लिए अपना प्रश्न संपादित कर सकते हैं? –
ऐसा नहीं है, मैंने अपनी पोस्ट में जोड़ा है कि मेरा कंसोल @ जॉन गॉर्डन जैसा दिखता है लेकिन मेरे पास वर्तमान में कोई अन्य परीक्षण नहीं है, इसके अलावा मैंने –
से ऊपर पोस्ट किए गए दो के अलावा, डीआर से पहले क्लास विधि फ़ंक्शन में इंडेंट है, क्या यह सही है? – pyCthon