3434from test import support
3535threading = support .import_module ('threading' )
3636
37+ import pytest
38+
39+
3740TRAVIS_MSG = 'These tests sporadically fail on travis-ci for some reason. (Threading?)'
3841
3942class NoLogRequestHandler (object ):
@@ -65,7 +68,7 @@ def stop(self):
6568 self .server .shutdown ()
6669
6770
68- @unittest . skipIf ('/home/travis' in __file__ , TRAVIS_MSG )
71+ @pytest . mark . skipif ('/home/travis' in __file__ , TRAVIS_MSG )
6972class BaseTestCase (unittest .TestCase ):
7073 def setUp (self ):
7174 self ._threads = support .threading_setup ()
@@ -87,7 +90,7 @@ def request(self, uri, method='GET', body=None, headers={}):
8790 return self .connection .getresponse ()
8891
8992
90- @unittest . skipIf ('/home/travis' in __file__ , TRAVIS_MSG )
93+ @pytest . mark . skipif ('/home/travis' in __file__ , TRAVIS_MSG )
9194class BaseHTTPServerTestCase (BaseTestCase ):
9295 class request_handler (NoLogRequestHandler , BaseHTTPRequestHandler ):
9396 protocol_version = 'HTTP/1.1'
@@ -219,7 +222,7 @@ def test_return_custom_status(self):
219222 res = self .con .getresponse ()
220223 self .assertEqual (res .status , 999 )
221224
222- @unittest .skip ('Unicode bug in Py2.7 email.parser.parsestr ?' )
225+ @pytest . mark .skip ('Unicode bug in Py2.7 email.parser.parsestr ?' )
223226 def test_latin1_header (self ):
224227 self .con .request ('LATINONEHEADER' , '/' , headers = {
225228 'X-Special-Incoming' : 'Ärger mit Unicode'
@@ -229,7 +232,7 @@ def test_latin1_header(self):
229232 self .assertEqual (res .read (), 'Ärger mit Unicode' .encode ('utf-8' ))
230233
231234
232- @unittest . skipIf ('/home/travis' in __file__ , TRAVIS_MSG )
235+ @pytest . mark . skipif ('/home/travis' in __file__ , TRAVIS_MSG )
233236class SimpleHTTPServerTestCase (BaseTestCase ):
234237 class request_handler (NoLogRequestHandler , SimpleHTTPRequestHandler ):
235238 pass
@@ -259,7 +262,7 @@ def check_status_and_reason(self, response, status, data=None):
259262 body = response .read ()
260263 self .assertTrue (response )
261264 self .assertEqual (response .status , status )
262- self .assertIsNotNone (response .reason )
265+ self .assertFalse (response .reason is None )
263266 if data :
264267 self .assertEqual (data , body )
265268
@@ -326,8 +329,8 @@ def test_invalid_requests(self):
326329"""
327330
328331
329- @unittest . skipIf ('/home/travis' in __file__ , TRAVIS_MSG )
330- @unittest . skipIf (hasattr (os , 'geteuid' ) and os .geteuid () == 0 ,
332+ @pytest . mark . skipif ('/home/travis' in __file__ , TRAVIS_MSG )
333+ @pytest . mark . skipif (hasattr (os , 'geteuid' ) and os .geteuid () == 0 ,
331334 "This test can't be run reliably as root (issue #13308)." )
332335class CGIHTTPServerTestCase (BaseTestCase ):
333336 class request_handler (NoLogRequestHandler , CGIHTTPRequestHandler ):
@@ -429,13 +432,13 @@ def test_url_collapse_path(self):
429432 msg = 'path = %r\n Got: %r\n Wanted: %r' %
430433 (path , actual , expected ))
431434
432- @unittest . expectedFailure
435+ @pytest . mark . xfail
433436 def test_headers_and_content (self ):
434437 res = self .request ('/cgi-bin/file1.py' )
435438 self .assertEqual ((b'Hello World' + self .linesep , 'text/html' , 200 ),
436439 (res .read (), res .getheader ('Content-type' ), res .status ))
437440
438- @unittest . expectedFailure
441+ @pytest . mark . xfail
439442 def test_post (self ):
440443 # Was: params = urllib.parse.urlencode(
441444 params = urllib .urlencode (
@@ -450,22 +453,22 @@ def test_invaliduri(self):
450453 res .read ()
451454 self .assertEqual (res .status , 404 )
452455
453- @unittest . expectedFailure
456+ @pytest . mark . xfail
454457 def test_authorization (self ):
455458 headers = {bytes (b'Authorization' ) : bytes (b'Basic ' ) +
456459 base64 .b64encode (bytes (b'username:pass' ))}
457460 res = self .request ('/cgi-bin/file1.py' , 'GET' , headers = headers )
458461 self .assertEqual ((b'Hello World' + self .linesep , 'text/html' , 200 ),
459462 (res .read (), res .getheader ('Content-type' ), res .status ))
460463
461- @unittest . expectedFailure
464+ @pytest . mark . xfail
462465 def test_no_leading_slash (self ):
463466 # http://bugs.python.org/issue2254
464467 res = self .request ('cgi-bin/file1.py' )
465468 self .assertEqual ((b'Hello World' + self .linesep , 'text/html' , 200 ),
466469 (res .read (), res .getheader ('Content-type' ), res .status ))
467470
468- @unittest . expectedFailure
471+ @pytest . mark . xfail
469472 def test_os_environ_is_not_altered (self ):
470473 signature = "Test CGI Server"
471474 os .environ ['SERVER_SOFTWARE' ] = signature
@@ -475,7 +478,7 @@ def test_os_environ_is_not_altered(self):
475478 self .assertEqual (os .environ ['SERVER_SOFTWARE' ], signature )
476479
477480
478- @unittest . skipIf ('/home/travis' in __file__ , TRAVIS_MSG )
481+ @pytest . mark . skipif ('/home/travis' in __file__ , TRAVIS_MSG )
479482class SocketlessRequestHandler (SimpleHTTPRequestHandler ):
480483 def __init__ (self ):
481484 self .get_called = False
@@ -491,7 +494,7 @@ def do_GET(self):
491494 def log_message (self , format , * args ):
492495 pass
493496
494- @unittest . skipIf ('/home/travis' in __file__ , TRAVIS_MSG )
497+ @pytest . mark . skipif ('/home/travis' in __file__ , TRAVIS_MSG )
495498class RejectingSocketlessRequestHandler (SocketlessRequestHandler ):
496499 def handle_expect_100 (self ):
497500 self .send_error (417 )
@@ -514,7 +517,7 @@ def numWrites(self):
514517 return len (self .datas )
515518
516519
517- @unittest . skipIf ('/home/travis' in __file__ , TRAVIS_MSG )
520+ @pytest . mark . skipif ('/home/travis' in __file__ , TRAVIS_MSG )
518521class BaseHTTPRequestHandlerTestCase (unittest .TestCase ):
519522 """Test the functionality of the BaseHTTPServer.
520523
@@ -673,7 +676,7 @@ def test_header_length(self):
673676 self .assertFalse (self .handler .get_called )
674677
675678
676- @unittest . skipIf ('/home/travis' in __file__ , TRAVIS_MSG )
679+ @pytest . mark . skipif ('/home/travis' in __file__ , TRAVIS_MSG )
677680class SimpleHTTPRequestHandlerTestCase (unittest .TestCase ):
678681 """ Test url parsing """
679682 def setUp (self ):
0 commit comments