emtest 0.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of emtest might be problematic. Click here for more details.
- emtest/__init__.py +7 -0
- emtest/pytest_utils.py +93 -0
- emtest/testing_utils.py +98 -0
- emtest-0.0.1.dist-info/METADATA +49 -0
- emtest-0.0.1.dist-info/RECORD +8 -0
- emtest-0.0.1.dist-info/WHEEL +5 -0
- emtest-0.0.1.dist-info/licenses/LICENCE +121 -0
- emtest-0.0.1.dist-info/top_level.txt +1 -0
emtest/__init__.py
ADDED
emtest/pytest_utils.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import os
|
|
5
|
+
import sys
|
|
6
|
+
from typing import Any, Optional
|
|
7
|
+
from _pytest.terminal import TerminalReporter
|
|
8
|
+
from _pytest.config import Config
|
|
9
|
+
from _pytest.reports import TestReport
|
|
10
|
+
from termcolor import colored
|
|
11
|
+
|
|
12
|
+
class MinimalReporter(TerminalReporter):
|
|
13
|
+
"""Custom pytest reporter that provides clean, minimal output with colored symbols.
|
|
14
|
+
|
|
15
|
+
This reporter suppresses most default pytest output and displays only:
|
|
16
|
+
- ✓ for passed tests (green)
|
|
17
|
+
- ✗ for failed tests (red)
|
|
18
|
+
- - for skipped tests (yellow)
|
|
19
|
+
"""
|
|
20
|
+
def __init__(self, config: Config) -> None:
|
|
21
|
+
super().__init__(config)
|
|
22
|
+
self._tw.hasmarkup = True # enables colored output safely
|
|
23
|
+
|
|
24
|
+
def _write_output(self, *args: Any, **kwargs: Any) -> None:
|
|
25
|
+
"""Override default output methods to suppress them."""
|
|
26
|
+
pass # override all default output methods
|
|
27
|
+
|
|
28
|
+
def _write_summary(self) -> None:
|
|
29
|
+
"""Override summary writing to suppress it."""
|
|
30
|
+
pass
|
|
31
|
+
|
|
32
|
+
def pytest_sessionstart(self, session: Any) -> None:
|
|
33
|
+
"""Override session start to suppress 'collected x items' message."""
|
|
34
|
+
# print("pytest_sessionstart")
|
|
35
|
+
pass # suppress "collected x items"
|
|
36
|
+
|
|
37
|
+
def pytest_runtest_logstart(self, nodeid: str, location: Any) -> None:
|
|
38
|
+
"""Override test start logging to suppress it."""
|
|
39
|
+
# print("pytest_runtest_logstart")
|
|
40
|
+
pass # suppress test start lines
|
|
41
|
+
|
|
42
|
+
def pytest_runtest_logreport(self, report: TestReport) -> None:
|
|
43
|
+
"""Display minimal test results with colored symbols."""
|
|
44
|
+
if report.when != "call":
|
|
45
|
+
return
|
|
46
|
+
|
|
47
|
+
test_name = report.nodeid.split("::")[-1]
|
|
48
|
+
if report.passed:
|
|
49
|
+
symbol = colored("✓", "green")
|
|
50
|
+
elif report.failed:
|
|
51
|
+
symbol = colored("✗", "red")
|
|
52
|
+
elif report.skipped:
|
|
53
|
+
symbol = colored("-", "yellow")
|
|
54
|
+
print(f"{symbol} {test_name}")
|
|
55
|
+
|
|
56
|
+
def summary_stats(self) -> None:
|
|
57
|
+
"""Override result counts to suppress them."""
|
|
58
|
+
pass # suppress result counts
|
|
59
|
+
|
|
60
|
+
def pytest_terminal_summary(self, terminalreporter: Any, exitstatus: int, config: Config) -> None:
|
|
61
|
+
"""Override final summary output to suppress it."""
|
|
62
|
+
pass # suppress final summary output
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def configure_pytest_reporter(config: Config) -> None:
|
|
66
|
+
"""Configure the minimal reporter if terminalreporter plugin is disabled.
|
|
67
|
+
|
|
68
|
+
Args:
|
|
69
|
+
config: Pytest configuration object
|
|
70
|
+
"""
|
|
71
|
+
# if terminalreporter plugin is disabled
|
|
72
|
+
if "no:terminalreporter" in config.option.plugins:
|
|
73
|
+
pluginmanager = config.pluginmanager
|
|
74
|
+
pluginmanager.register(MinimalReporter(config), "minimal-reporter")
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def run_pytest(test_path: str, breakpoints: bool, deactivate_pytest_output: bool = False, enable_print: bool = False) -> None:
|
|
78
|
+
"""Run pytest with customizable options for output control and debugging.
|
|
79
|
+
|
|
80
|
+
Args:
|
|
81
|
+
test_path: Path to the test file or directory to run
|
|
82
|
+
breakpoints: If True, enables pytest debugger (--pdb) on failures
|
|
83
|
+
deactivate_pytest_output: If True, uses minimal reporter instead of default output
|
|
84
|
+
enable_print: If True, enables print statements in tests (-s flag)
|
|
85
|
+
"""
|
|
86
|
+
args = []
|
|
87
|
+
if deactivate_pytest_output:
|
|
88
|
+
args += ["-p", "no:terminalreporter"]
|
|
89
|
+
if enable_print:
|
|
90
|
+
args.append("-s") # -s disables output capturing
|
|
91
|
+
if breakpoints:
|
|
92
|
+
args.append("--pdb")
|
|
93
|
+
os.system(f"{sys.executable} -m pytest {test_path} {' '.join(args)}")
|
emtest/testing_utils.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import os
|
|
4
|
+
import sys
|
|
5
|
+
import threading
|
|
6
|
+
import time
|
|
7
|
+
from time import sleep
|
|
8
|
+
from typing import List
|
|
9
|
+
from tqdm import TMonitor, tqdm
|
|
10
|
+
|
|
11
|
+
from types import ModuleType
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def add_path_to_python(src_path: str) -> None:
|
|
15
|
+
"""Add a directory to the Python path for importing modules.
|
|
16
|
+
|
|
17
|
+
Removes the path if it already exists, then inserts it at the beginning
|
|
18
|
+
of sys.path to ensure it takes priority over installed packages.
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
src_path: Directory path to add to Python path
|
|
22
|
+
|
|
23
|
+
Raises:
|
|
24
|
+
FileNotFoundError: If the path doesn't exist
|
|
25
|
+
NotADirectoryError: If the path is not a directory
|
|
26
|
+
"""
|
|
27
|
+
src_path = os.path.abspath(src_path)
|
|
28
|
+
if not os.path.exists(src_path):
|
|
29
|
+
raise FileNotFoundError(f"The path doesn't exist: {src_path}")
|
|
30
|
+
if not os.path.isdir(src_path):
|
|
31
|
+
raise NotADirectoryError(f"The path doesn't exist: {src_path}")
|
|
32
|
+
|
|
33
|
+
if src_path in sys.path:
|
|
34
|
+
sys.path.remove(src_path)
|
|
35
|
+
sys.path.insert(0, src_path)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def assert_is_loaded_from_source(
|
|
39
|
+
source_dir: str, module: ModuleType, print_confirmation=False
|
|
40
|
+
) -> None:
|
|
41
|
+
"""Assert a module is loaded from source code, not an installation.
|
|
42
|
+
|
|
43
|
+
Asserts that the loaded module's source code is located within the given
|
|
44
|
+
directory, regardless of whether it's file is located in that folder or is
|
|
45
|
+
nested in subfolders.
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
source_dir: a directory in which the module's source should be
|
|
49
|
+
module: the module to check
|
|
50
|
+
"""
|
|
51
|
+
module_path = os.path.abspath(module.__file__)
|
|
52
|
+
source_path = os.path.abspath(source_dir)
|
|
53
|
+
assert (
|
|
54
|
+
source_path in module_path
|
|
55
|
+
), (
|
|
56
|
+
f"The module `{module.__name__}` has been loaded from an installion, "
|
|
57
|
+
"not this source code!\n"
|
|
58
|
+
f"Desired source dir: {source_path}\n"
|
|
59
|
+
f"Loaded module path: {module_path}\n"
|
|
60
|
+
)
|
|
61
|
+
if print_confirmation:
|
|
62
|
+
print(f"Using module {module.__name__} from {module_path}")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def polite_wait(n_sec: int) -> None:
|
|
66
|
+
"""Wait for the given duration, displaying a progress bar.
|
|
67
|
+
|
|
68
|
+
Args:
|
|
69
|
+
n_sec: Number of seconds to wait
|
|
70
|
+
"""
|
|
71
|
+
# print(f"{n_sec}s patience...")
|
|
72
|
+
for i in tqdm(range(n_sec), leave=False):
|
|
73
|
+
time.sleep(1)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def await_thread_cleanup(timeout: int = 5) -> bool:
|
|
77
|
+
"""Wait for all threads to exit, with a timeout and progress bar.
|
|
78
|
+
|
|
79
|
+
Args:
|
|
80
|
+
timeout: Maximum seconds to wait for thread cleanup
|
|
81
|
+
|
|
82
|
+
Returns:
|
|
83
|
+
True if only the main thread remains, False if other threads persist
|
|
84
|
+
"""
|
|
85
|
+
def get_threads() -> List[threading.Thread]:
|
|
86
|
+
"""Get all active threads except tqdm monitor threads."""
|
|
87
|
+
return [
|
|
88
|
+
x for x in threading.enumerate() if not isinstance(x, TMonitor)
|
|
89
|
+
]
|
|
90
|
+
|
|
91
|
+
for i in tqdm(range(timeout), leave=False):
|
|
92
|
+
if len(get_threads()) == 1:
|
|
93
|
+
break
|
|
94
|
+
sleep(1)
|
|
95
|
+
|
|
96
|
+
return len(get_threads()) == 1
|
|
97
|
+
|
|
98
|
+
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: emtest
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Testing utilities which I find useful.
|
|
5
|
+
Author-email: Emendir <dev@emendir.tech>
|
|
6
|
+
License-Expression: CC0-1.0
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Operating System :: OS Independent
|
|
9
|
+
Requires-Python: >=3.6
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENCE
|
|
12
|
+
Requires-Dist: tqdm
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
# emtest - Python Testing Utilities
|
|
16
|
+
|
|
17
|
+
A Python package providing testing utilities.
|
|
18
|
+
|
|
19
|
+
## Features
|
|
20
|
+
|
|
21
|
+
### 🎨 Clean Test Output for Pytest
|
|
22
|
+
- **MinimalReporter**: Custom pytest reporter with clean, colored output using simple symbols (✓/✗/-)
|
|
23
|
+
- **Configurable Output**: Toggle between minimal and standard pytest output modes
|
|
24
|
+
|
|
25
|
+
### 🔧 Development Utilities
|
|
26
|
+
- **Source Path Management**: Dynamically add directories to Python path for testing source code
|
|
27
|
+
- **Module Source Validation**: Ensure modules are loaded from source directories (not installed packages)
|
|
28
|
+
- **Thread Cleanup Monitoring**: Wait for and verify proper thread cleanup in tests
|
|
29
|
+
|
|
30
|
+
### ⚡ Enhanced Test Execution
|
|
31
|
+
- **Dual Execution Pattern**: Run tests both as pytest tests and standalone Python scripts
|
|
32
|
+
- **Breakpoint Integration**: Easy debugging with pytest's `--pdb` integration
|
|
33
|
+
- **Progress Indicators**: Visual progress bars for waiting operations
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
pip install emtest
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Usage
|
|
42
|
+
|
|
43
|
+
See the `examples/` directory for complete working examples showing:
|
|
44
|
+
- Basic test setup with `conftest.py`
|
|
45
|
+
- Dual execution pattern implementation
|
|
46
|
+
- Source loading validation
|
|
47
|
+
- Thread cleanup testing
|
|
48
|
+
|
|
49
|
+
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
emtest/__init__.py,sha256=tC-Hx6hKUVswMSIik-RwLF4fO4rDaZXi05DzDkixoCE,195
|
|
2
|
+
emtest/pytest_utils.py,sha256=0vVNw6P4FdS7BsX18GMXK7bne-hfSNWiLtRS0sLiZOA,3486
|
|
3
|
+
emtest/testing_utils.py,sha256=uZeEw4EKhy_2sUIzUPF1kvfVfyis3mF7Q5SSj9uxzCU,2899
|
|
4
|
+
emtest-0.0.1.dist-info/licenses/LICENCE,sha256=bUia9ikmYtnjbTTOSUI3hJhKX25B17WPSbASZN9Z-gM,7047
|
|
5
|
+
emtest-0.0.1.dist-info/METADATA,sha256=UWQ9-OOa4u74B_kwP8BG2-2c77u1Mjod5mXS71TnGOM,1570
|
|
6
|
+
emtest-0.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
7
|
+
emtest-0.0.1.dist-info/top_level.txt,sha256=8yXylA__VmNeIDW3MBOmSiOpUCZoEprrys-qdB54CLo,7
|
|
8
|
+
emtest-0.0.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
Creative Commons Legal Code
|
|
2
|
+
|
|
3
|
+
CC0 1.0 Universal
|
|
4
|
+
|
|
5
|
+
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
|
6
|
+
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
|
7
|
+
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
|
8
|
+
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
|
9
|
+
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
|
10
|
+
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
|
11
|
+
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
|
12
|
+
HEREUNDER.
|
|
13
|
+
|
|
14
|
+
Statement of Purpose
|
|
15
|
+
|
|
16
|
+
The laws of most jurisdictions throughout the world automatically confer
|
|
17
|
+
exclusive Copyright and Related Rights (defined below) upon the creator
|
|
18
|
+
and subsequent owner(s) (each and all, an "owner") of an original work of
|
|
19
|
+
authorship and/or a database (each, a "Work").
|
|
20
|
+
|
|
21
|
+
Certain owners wish to permanently relinquish those rights to a Work for
|
|
22
|
+
the purpose of contributing to a commons of creative, cultural and
|
|
23
|
+
scientific works ("Commons") that the public can reliably and without fear
|
|
24
|
+
of later claims of infringement build upon, modify, incorporate in other
|
|
25
|
+
works, reuse and redistribute as freely as possible in any form whatsoever
|
|
26
|
+
and for any purposes, including without limitation commercial purposes.
|
|
27
|
+
These owners may contribute to the Commons to promote the ideal of a free
|
|
28
|
+
culture and the further production of creative, cultural and scientific
|
|
29
|
+
works, or to gain reputation or greater distribution for their Work in
|
|
30
|
+
part through the use and efforts of others.
|
|
31
|
+
|
|
32
|
+
For these and/or other purposes and motivations, and without any
|
|
33
|
+
expectation of additional consideration or compensation, the person
|
|
34
|
+
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
|
|
35
|
+
is an owner of Copyright and Related Rights in the Work, voluntarily
|
|
36
|
+
elects to apply CC0 to the Work and publicly distribute the Work under its
|
|
37
|
+
terms, with knowledge of his or her Copyright and Related Rights in the
|
|
38
|
+
Work and the meaning and intended legal effect of CC0 on those rights.
|
|
39
|
+
|
|
40
|
+
1. Copyright and Related Rights. A Work made available under CC0 may be
|
|
41
|
+
protected by copyright and related or neighboring rights ("Copyright and
|
|
42
|
+
Related Rights"). Copyright and Related Rights include, but are not
|
|
43
|
+
limited to, the following:
|
|
44
|
+
|
|
45
|
+
i. the right to reproduce, adapt, distribute, perform, display,
|
|
46
|
+
communicate, and translate a Work;
|
|
47
|
+
ii. moral rights retained by the original author(s) and/or performer(s);
|
|
48
|
+
iii. publicity and privacy rights pertaining to a person's image or
|
|
49
|
+
likeness depicted in a Work;
|
|
50
|
+
iv. rights protecting against unfair competition in regards to a Work,
|
|
51
|
+
subject to the limitations in paragraph 4(a), below;
|
|
52
|
+
v. rights protecting the extraction, dissemination, use and reuse of data
|
|
53
|
+
in a Work;
|
|
54
|
+
vi. database rights (such as those arising under Directive 96/9/EC of the
|
|
55
|
+
European Parliament and of the Council of 11 March 1996 on the legal
|
|
56
|
+
protection of databases, and under any national implementation
|
|
57
|
+
thereof, including any amended or successor version of such
|
|
58
|
+
directive); and
|
|
59
|
+
vii. other similar, equivalent or corresponding rights throughout the
|
|
60
|
+
world based on applicable law or treaty, and any national
|
|
61
|
+
implementations thereof.
|
|
62
|
+
|
|
63
|
+
2. Waiver. To the greatest extent permitted by, but not in contravention
|
|
64
|
+
of, applicable law, Affirmer hereby overtly, fully, permanently,
|
|
65
|
+
irrevocably and unconditionally waives, abandons, and surrenders all of
|
|
66
|
+
Affirmer's Copyright and Related Rights and associated claims and causes
|
|
67
|
+
of action, whether now known or unknown (including existing as well as
|
|
68
|
+
future claims and causes of action), in the Work (i) in all territories
|
|
69
|
+
worldwide, (ii) for the maximum duration provided by applicable law or
|
|
70
|
+
treaty (including future time extensions), (iii) in any current or future
|
|
71
|
+
medium and for any number of copies, and (iv) for any purpose whatsoever,
|
|
72
|
+
including without limitation commercial, advertising or promotional
|
|
73
|
+
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
|
|
74
|
+
member of the public at large and to the detriment of Affirmer's heirs and
|
|
75
|
+
successors, fully intending that such Waiver shall not be subject to
|
|
76
|
+
revocation, rescission, cancellation, termination, or any other legal or
|
|
77
|
+
equitable action to disrupt the quiet enjoyment of the Work by the public
|
|
78
|
+
as contemplated by Affirmer's express Statement of Purpose.
|
|
79
|
+
|
|
80
|
+
3. Public License Fallback. Should any part of the Waiver for any reason
|
|
81
|
+
be judged legally invalid or ineffective under applicable law, then the
|
|
82
|
+
Waiver shall be preserved to the maximum extent permitted taking into
|
|
83
|
+
account Affirmer's express Statement of Purpose. In addition, to the
|
|
84
|
+
extent the Waiver is so judged Affirmer hereby grants to each affected
|
|
85
|
+
person a royalty-free, non transferable, non sublicensable, non exclusive,
|
|
86
|
+
irrevocable and unconditional license to exercise Affirmer's Copyright and
|
|
87
|
+
Related Rights in the Work (i) in all territories worldwide, (ii) for the
|
|
88
|
+
maximum duration provided by applicable law or treaty (including future
|
|
89
|
+
time extensions), (iii) in any current or future medium and for any number
|
|
90
|
+
of copies, and (iv) for any purpose whatsoever, including without
|
|
91
|
+
limitation commercial, advertising or promotional purposes (the
|
|
92
|
+
"License"). The License shall be deemed effective as of the date CC0 was
|
|
93
|
+
applied by Affirmer to the Work. Should any part of the License for any
|
|
94
|
+
reason be judged legally invalid or ineffective under applicable law, such
|
|
95
|
+
partial invalidity or ineffectiveness shall not invalidate the remainder
|
|
96
|
+
of the License, and in such case Affirmer hereby affirms that he or she
|
|
97
|
+
will not (i) exercise any of his or her remaining Copyright and Related
|
|
98
|
+
Rights in the Work or (ii) assert any associated claims and causes of
|
|
99
|
+
action with respect to the Work, in either case contrary to Affirmer's
|
|
100
|
+
express Statement of Purpose.
|
|
101
|
+
|
|
102
|
+
4. Limitations and Disclaimers.
|
|
103
|
+
|
|
104
|
+
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
|
105
|
+
surrendered, licensed or otherwise affected by this document.
|
|
106
|
+
b. Affirmer offers the Work as-is and makes no representations or
|
|
107
|
+
warranties of any kind concerning the Work, express, implied,
|
|
108
|
+
statutory or otherwise, including without limitation warranties of
|
|
109
|
+
title, merchantability, fitness for a particular purpose, non
|
|
110
|
+
infringement, or the absence of latent or other defects, accuracy, or
|
|
111
|
+
the present or absence of errors, whether or not discoverable, all to
|
|
112
|
+
the greatest extent permissible under applicable law.
|
|
113
|
+
c. Affirmer disclaims responsibility for clearing rights of other persons
|
|
114
|
+
that may apply to the Work or any use thereof, including without
|
|
115
|
+
limitation any person's Copyright and Related Rights in the Work.
|
|
116
|
+
Further, Affirmer disclaims responsibility for obtaining any necessary
|
|
117
|
+
consents, permissions or other rights required for any use of the
|
|
118
|
+
Work.
|
|
119
|
+
d. Affirmer understands and acknowledges that Creative Commons is not a
|
|
120
|
+
party to this document and has no duty or obligation with respect to
|
|
121
|
+
this CC0 or use of the Work.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
emtest
|