change: make converted referenced pytest files always relative to project RootDir

This commit is contained in:
debugtalk
2020-06-20 23:53:45 +08:00
parent 4f405d1620
commit 18e9b772fd
15 changed files with 132 additions and 193 deletions

View File

@@ -1,4 +1,5 @@
import io
import os
import sys
import unittest
@@ -40,10 +41,12 @@ class TestCli(unittest.TestCase):
self.assertIn(__description__, self.captured_output.getvalue().strip())
def test_debug_pytest(self):
exit_code = pytest.main(
[
"-s",
"examples/postman_echo/request_methods/request_with_testcase_reference_test.py",
]
)
self.assertEqual(exit_code, 0)
cwd = os.getcwd()
try:
os.chdir(os.path.join(cwd, "examples", "postman_echo"))
exit_code = pytest.main(
["-s", "request_methods/request_with_testcase_reference_test.py",]
)
self.assertEqual(exit_code, 0)
finally:
os.chdir(cwd)

View File

@@ -6,7 +6,7 @@ config:
teststeps:
-
name: request with functions
testcase: 1.yml
testcase: a-b.c/1.yml
export:
- session_foo2
-

View File

View File

@@ -8,6 +8,7 @@ from httprunner.make import (
make_config_chain_style,
make_teststep_chain_style,
pytest_files_run_set,
ensure_file_abs_path_valid,
)
from httprunner import loader
@@ -64,7 +65,7 @@ class TestMake(unittest.TestCase):
content = f.read()
self.assertIn(
"""
from examples.postman_echo.request_methods.request_with_functions_test import (
from request_methods.request_with_functions_test import (
TestCaseRequestWithFunctions as RequestWithFunctions,
)
""",
@@ -90,53 +91,57 @@ from examples.postman_echo.request_methods.request_with_functions_test import (
testcase_python_list,
)
def test_ensure_file_path_valid(self):
self.assertEqual(
ensure_file_abs_path_valid(
os.path.join(os.getcwd(), "tests", "data", "a-b.c", "2 3.yml")
),
os.path.join(os.getcwd(), "tests", "data", "a_b_c", "T2_3.yml"),
)
loader.project_meta = None
self.assertEqual(
ensure_file_abs_path_valid(
os.path.join(os.getcwd(), "examples", "postman_echo", "request_methods")
),
os.path.join(os.getcwd(), "examples", "postman_echo", "request_methods"),
)
loader.project_meta = None
self.assertEqual(
ensure_file_abs_path_valid(os.path.join(os.getcwd(), "README.md")),
os.path.join(os.getcwd(), "README.md"),
)
loader.project_meta = None
self.assertEqual(
ensure_file_abs_path_valid(os.getcwd()), os.getcwd(),
)
loader.project_meta = None
self.assertEqual(
ensure_file_abs_path_valid(
os.path.join(os.getcwd(), "tests", "data", ".csv")
),
os.path.join(os.getcwd(), "tests", "data", ".csv"),
)
def test_convert_testcase_path(self):
self.assertEqual(
convert_testcase_path(os.path.join(os.getcwd(), "mubu.login.yml")),
(os.path.join(os.getcwd(), "mubu_login_test.py"), "MubuLogin"),
)
self.assertEqual(
convert_testcase_path(
os.path.join(os.getcwd(), os.path.join("path", "to", "mubu.login.yml"))
os.path.join(os.getcwd(), "tests", "data", "a-b.c", "2 3.yml")
),
(
os.path.join(
os.getcwd(), os.path.join("path", "to", "mubu_login_test.py")
),
"MubuLogin",
os.path.join(os.getcwd(), "tests", "data", "a_b_c", "T2_3_test.py"),
"T23",
),
)
self.assertEqual(
convert_testcase_path(
os.path.join(os.getcwd(), "path", "to 2", "mubu.login.yml")
os.path.join(os.getcwd(), "tests", "data", "a-b.c", "中文case.yml")
),
(
os.path.join(
os.getcwd(), os.path.join("path", "to_2", "mubu_login_test.py")
os.getcwd(),
os.path.join("tests", "data", "a_b_c", "中文case_test.py"),
),
"MubuLogin",
),
)
self.assertEqual(
convert_testcase_path(
os.path.join(os.getcwd(), "path", "to-2", "mubu login.yml")
),
(
os.path.join(
os.getcwd(), os.path.join("path", "to_2", "mubu_login_test.py")
),
"MubuLogin",
),
)
self.assertEqual(
convert_testcase_path(
os.path.join(os.getcwd(), "path", "to.2", "幕布login.yml")
),
(
os.path.join(
os.getcwd(), os.path.join("path", "to_2", "幕布login_test.py")
),
"幕布Login",
"中文Case",
),
)

View File

@@ -35,6 +35,6 @@ class TestHttpRunner(unittest.TestCase):
exit_code = main_run(["tests/data/a-b.c/2 3.yml"])
self.assertEqual(exit_code, 0)
self.assertTrue(os.path.exists("tests/data/a_b_c/__init__.py"))
self.assertTrue(os.path.exists("tests/data/a_b_c/debugtalk.py"))
self.assertTrue(os.path.exists("tests/data/debugtalk.py"))
self.assertTrue(os.path.exists("tests/data/a_b_c/T1_test.py"))
self.assertTrue(os.path.exists("tests/data/a_b_c/T2_3_test.py"))

View File

@@ -5,7 +5,6 @@ import unittest
from httprunner import loader, utils
from httprunner.utils import (
ensure_file_abs_path_valid,
ExtendJSONEncoder,
override_config_variables,
)
@@ -105,41 +104,6 @@ class TestUtils(unittest.TestCase):
["A", "D", "C", "B"],
)
def test_ensure_file_path_valid(self):
self.assertEqual(
ensure_file_abs_path_valid(
os.path.join(os.getcwd(), "examples", "a-b.c", "d f", "hardcode.yml")
),
os.path.join(os.getcwd(), "examples", "a_b_c", "d_f", "hardcode.yml"),
)
self.assertEqual(
ensure_file_abs_path_valid(os.path.join(os.getcwd(), "1", "2B", "3.yml")),
os.path.join(os.getcwd(), "T1", "T2B", "T3.yml"),
)
self.assertEqual(
ensure_file_abs_path_valid(
os.path.join(os.getcwd(), "examples", "a-b.c", "2B", "hardcode.yml")
),
os.path.join(os.getcwd(), "examples", "a_b_c", "T2B", "hardcode.yml"),
)
self.assertEqual(
ensure_file_abs_path_valid(
os.path.join(os.getcwd(), "examples", "postman_echo", "request_methods")
),
os.path.join(os.getcwd(), "examples", "postman_echo", "request_methods"),
)
self.assertEqual(
ensure_file_abs_path_valid(os.path.join(os.getcwd(), "test.yml")),
os.path.join(os.getcwd(), "test.yml"),
)
self.assertEqual(
ensure_file_abs_path_valid(os.getcwd()), os.getcwd(),
)
self.assertEqual(
ensure_file_abs_path_valid(os.path.join(os.getcwd(), "demo", ".csv")),
os.path.join(os.getcwd(), "demo", ".csv"),
)
def test_safe_dump_json(self):
class A(object):
pass