Skip to content

Commit 5f4df01

Browse files
authored
Merge pull request #8 from eldaduzman/fix-decorator-sig
fix decorator signature
2 parents 017bd5b + 0443b48 commit 5f4df01

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,3 +337,4 @@ $RECYCLE.BIN/
337337
# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)
338338

339339
.vscode/
340+
localstuff/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Decorate your unittest class with `@perf_unit_test_class` to turn standard unit
2929
from perf_unit import perf_unit_test_class
3030
import unittest
3131

32-
@perf_unit_test_class()
32+
@perf_unit_test_class
3333
class MyTestCase(unittest.TestCase):
3434

3535
def test_example1(self):

src/perf_unit/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def run_single_iteration(
6161

6262

6363
def perf_unit_test_class(
64+
*args,
6465
how_many_threads: int = 30,
6566
total_number_of_method_executions: int = 100,
6667
upper_median_threashold_in_milliseconds: int = 500,
@@ -91,7 +92,7 @@ def wrapped_method(*args, **kwargs):
9192
)
9293
)
9394

94-
execution_times = [future.result() for future in futures]
95+
execution_times = tuple([future.result() for future in futures])
9596

9697
median_time = statistics.median(execution_times)
9798

@@ -121,4 +122,7 @@ def wrapped_method(*args, **kwargs):
121122

122123
return cls
123124

125+
if len(args) == 1:
126+
return modify_test_class(args[0])
127+
124128
return modify_test_class

utests/test_basic.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ def test_method(false_self):
2121
self.assertTrue(result.wasSuccessful())
2222

2323
def test_should_fail_due_too_high_latency(self):
24-
@perf_unit_test_class(how_many_threads=50, upper_median_threashold_in_milliseconds=1)
24+
@perf_unit_test_class(
25+
how_many_threads=50, upper_median_threashold_in_milliseconds=1
26+
)
2527
class SomeTestClass(TestCase):
2628
def test_method(false_self):
2729
time.sleep(random.randint(200, 600) / 1000)
@@ -50,6 +52,19 @@ def test_class_has_no_test_methods(self):
5052
class SomeTestClass(TestCase):
5153
pass
5254

55+
def test_decorators_with_no_inputs(self):
56+
@perf_unit_test_class
57+
class SomeTestClass(TestCase):
58+
def test_method(false_self):
59+
pass
60+
61+
suite = TestLoader().loadTestsFromTestCase(SomeTestClass)
62+
63+
runner = TextTestRunner()
64+
result = runner.run(suite)
65+
result.printErrors()
66+
self.assertTrue(result.wasSuccessful())
67+
5368

5469
if __name__ == "__main__":
5570
main()

0 commit comments

Comments
 (0)