diff --git a/CHANGELOG b/CHANGELOG index c2f53fef6..88ac07419 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -17,6 +17,9 @@ NEXT - fix issue544 by only removing "@NUM" at the end of "::" separated parts and if the part has an ".py" extension +- don't use py.std import helper, rather import things directly. + Thanks Bruno Oliveira. + 2.6 ----------------------------------- diff --git a/_pytest/__init__.py b/_pytest/__init__.py index f8d003fcf..35cf9d652 100644 --- a/_pytest/__init__.py +++ b/_pytest/__init__.py @@ -1,2 +1,2 @@ # -__version__ = '2.6.1.dev1' +__version__ = '2.6.1.dev2' diff --git a/_pytest/genscript.py b/_pytest/genscript.py index 7dddcfc57..9104dcab8 100755 --- a/_pytest/genscript.py +++ b/_pytest/genscript.py @@ -1,9 +1,6 @@ """ generate a single-file self-contained version of pytest """ -import base64 -import pickle import py import sys -import zlib def find_toplevel(name): @@ -33,6 +30,7 @@ def pkg_to_mapping(name): return name2src def compress_mapping(mapping): + import base64, pickle, zlib data = pickle.dumps(mapping, 2) data = zlib.compress(data, 9) data = base64.encodestring(data) diff --git a/_pytest/junitxml.py b/_pytest/junitxml.py index 2a86c8dee..2371e17ba 100644 --- a/_pytest/junitxml.py +++ b/_pytest/junitxml.py @@ -2,8 +2,6 @@ Based on initial code from Ross Lawley. """ -import codecs - import py import os import re @@ -11,20 +9,13 @@ import sys import time # Python 2.X and 3.X compatibility -try: - unichr(65) -except NameError: +if sys.version_info[0] < 3: + from codecs import open +else: unichr = chr -try: - unicode('A') -except NameError: unicode = str -try: - long(1) -except NameError: long = int - class Junit(py.xml.Namespace): pass @@ -207,11 +198,7 @@ class LogXML(object): self.suite_start_time = time.time() def pytest_sessionfinish(self): - if sys.version_info[0] < 3: - logfile = codecs.open(self.logfile, 'w', encoding='utf-8') - else: - logfile = open(self.logfile, 'w', encoding='utf-8') - + logfile = open(self.logfile, 'w', encoding='utf-8') suite_stop_time = time.time() suite_time_delta = suite_stop_time - self.suite_start_time numtests = self.passed + self.failed diff --git a/_pytest/unittest.py b/_pytest/unittest.py index 666519129..af2aa9357 100644 --- a/_pytest/unittest.py +++ b/_pytest/unittest.py @@ -1,7 +1,6 @@ """ discovery and running of std-library "unittest" style tests. """ from __future__ import absolute_import import traceback -import unittest import sys import pytest @@ -12,22 +11,15 @@ import py from _pytest.python import transfer_markers -def is_unittest(obj): - """Is obj a subclass of unittest.TestCase?""" - unittest = sys.modules.get('unittest') - if unittest is None: - return # nobody can have derived unittest.TestCase - try: - return issubclass(obj, unittest.TestCase) - except KeyboardInterrupt: - raise - except: - return False - - def pytest_pycollect_makeitem(collector, name, obj): - if is_unittest(obj): - return UnitTestCase(name, parent=collector) + # has unittest been imported and is obj a subclass of its TestCase? + try: + if not issubclass(obj, sys.modules["unittest"].TestCase): + return + except Exception: + return + # yes, so let's collect it + return UnitTestCase(name, parent=collector) class UnitTestCase(pytest.Class): @@ -47,11 +39,12 @@ class UnitTestCase(pytest.Class): super(UnitTestCase, self).setup() def collect(self): + from unittest import TestLoader cls = self.obj if not getattr(cls, "__test__", True): return self.session._fixturemanager.parsefactories(self, unittest=True) - loader = unittest.TestLoader() + loader = TestLoader() module = self.getparent(pytest.Module).obj foundsomething = False for name in loader.getTestCaseNames(self.obj): diff --git a/setup.py b/setup.py index e3ad2ad15..1c34bb2c0 100644 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ def main(): name='pytest', description='pytest: simple powerful testing with Python', long_description=long_description, - version='2.6.1.dev1', + version='2.6.1.dev2', url='http://pytest.org', license='MIT license', platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],