Skip to content

Commit

Permalink
Fix of inability to function properly when the current dir didn't mat…
Browse files Browse the repository at this point in the history
…ch rootdir. Bump to v2.0.2
  • Loading branch information
tarpas committed Mar 25, 2023
1 parent 95ea08a commit e517517
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "pytest-testmon"
authors = [
{ name = "Tibor Arpas", email = "[email protected]" },
]
version = "2.0.1"
version = "2.0.2"
description = "selects tests affected by changed files and methods"
readme = "README.md"
requires-python = ">=3.7"
Expand Down Expand Up @@ -60,8 +60,6 @@ exclude = '''
)
'''

[project.scripts]
tmnetc = "testmon.tmnetc:main"

[project.entry-points.pytest11]
pytest-testmon = "testmon.pytest_testmon"
5 changes: 3 additions & 2 deletions testmon/pytest_testmon.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def init_testmon_data(config):
rpc_proxy = xmlrpc.client.ServerProxy(project_url, allow_none=True)

testmon_data = TestmonData(
rootdir=config.rootdir.strpath,
database=rpc_proxy,
environment=environment,
system_packages=packages,
Expand Down Expand Up @@ -479,11 +480,11 @@ def pytest_terminal_summary(self):
)

try:
tests_all_ratio = f"{100.0*total_saved_tests/total_tests_all:.0f}"
tests_all_ratio = f"{100.0 * total_saved_tests / total_tests_all:.0f}"
except ZeroDivisionError:
tests_all_ratio = "0"
try:
tests_current_ratio = f"{100.0*run_saved_tests/run_all_tests:.0f}"
tests_current_ratio = f"{100.0 * run_saved_tests / run_all_tests:.0f}"
except ZeroDivisionError:
tests_current_ratio = "0"
msg = f"this run: {run_saved_tests}/{run_all_tests} ({tests_current_ratio}%) tests, "
Expand Down
14 changes: 8 additions & 6 deletions testmon/testmon_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class TestmonException(Exception):


class SourceTree:
def __init__(self, rootdir="", packages=None):
def __init__(self, rootdir, packages=None):
self.rootdir = rootdir
self.packages = packages
self.cache = {}
Expand Down Expand Up @@ -128,13 +128,15 @@ class TestmonData:

def __init__(
self,
rootdir,
database=None,
environment=None,
system_packages=None,
python_version=None,
):
self.rootdir = rootdir
self.environment = environment if environment else "default"
self.source_tree = SourceTree(rootdir="")
self.source_tree = SourceTree(rootdir=rootdir)
if system_packages is None:
system_packages = ", ".join(
sorted(str(p) for p in pkg_resources.working_set or [])
Expand All @@ -145,7 +147,7 @@ def __init__(
if database:
self.db = database
else:
self.db = db.DB(get_data_file_path())
self.db = db.DB(os.path.join(self.rootdir, get_data_file_path()))

try:
result = self.db.initiate_execution(
Expand All @@ -156,7 +158,7 @@ def __init__(
"%s error when communication with testmon.net. (falling back to .testmondata locally)",
exc,
)
self.db = db.DB(get_data_file_path())
self.db = db.DB(os.path.join(self.rootdir, get_data_file_path()))

self.exec_id = result["exec_id"]
self.all_files = set(result["filenames"])
Expand All @@ -180,7 +182,7 @@ def get_tests_fingerprints(self, nodes_files_lines, reports):
deps_n_outcomes = {"deps": []}

for filename, covered in nodes_files_lines[context].items():
if os.path.exists(filename):
if os.path.exists(os.path.join(self.rootdir, filename)):
module = self.source_tree.get_file(filename)
fingerprint = create_fingerprint(module, covered)
deps_n_outcomes["deps"].append(
Expand Down Expand Up @@ -340,7 +342,7 @@ def cached_relpath(path, basepath):
class TestmonCollector:
coverage_stack = []

def __init__(self, rootdir=".", testmon_labels=None, cov_plugin=None):
def __init__(self, rootdir, testmon_labels=None, cov_plugin=None):
try:
from testmon.testmon_core import (
Testmon as UberTestmon,
Expand Down

0 comments on commit e517517

Please sign in to comment.