diff --git a/pyserv/__init__.py b/pyserv/__init__.py index 5393607..6d8c414 100644 --- a/pyserv/__init__.py +++ b/pyserv/__init__.py @@ -3,8 +3,8 @@ """ import logging -import os import threading +from functools import partial from http.server import HTTPServer, SimpleHTTPRequestHandler from socketserver import ThreadingMixIn from urllib.parse import urlparse @@ -88,12 +88,11 @@ def __init__(self, iface, port, directory): self.iface = iface self.port = int(port) self.directory = directory - self.handler = GetHandler + self.handler = partial(GetHandler, directory=self.directory) self.server = ThreadingHTTPServer((self.iface, self.port), self.handler) def run(self): """Start main server thread""" - os.chdir(self.directory) self.server.serve_forever() def stop(self): diff --git a/tests/test_handler.py b/tests/test_handler.py index d43bd4c..7ade2ab 100644 --- a/tests/test_handler.py +++ b/tests/test_handler.py @@ -1,14 +1,16 @@ -# -*- coding: utf-8 -*- import pathlib +import sys import unittest import urllib.request import httptest +import pytest from pyserv import GetHandler FILE_PATH = pathlib.Path(__file__) +@pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7 or higher") class TestHTTPTestMethods(unittest.TestCase): @httptest.Server(