Skip to content

Commit

Permalink
Merge pull request #80 from AnyBody-Research-Group/pytest54
Browse files Browse the repository at this point in the history
Pytest54
  • Loading branch information
melund authored Apr 16, 2020
2 parents b388674 + eb3d3e2 commit 7541eca
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ v1.4.2



v1.4.2
=============

**Fixed:**

* Fixed a bug with the pytest plugin not working with pytest 5.4



v1.4.1
=============

Expand Down
2 changes: 1 addition & 1 deletion anypytools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"NORMAL_PRIORITY_CLASS",
]

__version__ = "1.4.1"
__version__ = "1.4.2"


def print_versions():
Expand Down
16 changes: 12 additions & 4 deletions anypytools/abcutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ def execute_anybodycon(
_subprocess_container.add(proc.pid)
try:
proc.wait(timeout=timeout)
retcode = ctypes.c_int32(proc.returncode).value
except TimeoutExpired:
proc.terminate()
proc.communicate()
Expand All @@ -228,9 +229,15 @@ def execute_anybodycon(
logfile.write(
"\nERROR: AnyPyTools : Timeout after {:d} sec.".format(int(timeout))
)
proc.returncode = 0
_subprocess_container.remove(proc.pid)
retcode = ctypes.c_int32(proc.returncode).value
retcode = 0
except KeyboardInterrupt:
proc.terminate()
proc.communicate()
retcode = _KILLED_BY_ANYPYTOOLS
raise
finally:
_subprocess_container.remove(proc.pid)

if retcode == _KILLED_BY_ANYPYTOOLS:
logfile.write("\nAnybodycon.exe was interrupted by AnyPyTools")
elif retcode == _NO_LICENSES_AVAILABLE:
Expand Down Expand Up @@ -362,7 +369,7 @@ def tasklist_summery(tasklist: List[_Task]) -> str:
out += f", Failed: {len(failed_tasks):d}"
if len(unfinished_tasks):
out += f", Not processed: {len(unfinished_tasks):d}"
return out + "\n"
return out


def task_summery(task: _Task) -> str:
Expand Down Expand Up @@ -768,6 +775,7 @@ def start_macro(
pbar.container.children[0].bar_style = "danger"
pbar.update()
except KeyboardInterrupt as e:
_subprocess_container.stop_all = True
tqdm.write("KeyboardInterrupt: User aborted")
time.sleep(1)
finally:
Expand Down
13 changes: 7 additions & 6 deletions anypytools/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import pytest

from _pytest.tmpdir import TempdirFactory, TempPathFactory

from anypytools import AnyPyProcess, macro_commands
from anypytools.tools import (
get_anybodycon_path,
Expand Down Expand Up @@ -209,12 +211,11 @@ def pytest_configure(config):
config.pluginmanager.register(DeferPlugin())



def pytest_collection_modifyitems(items, config):
selected_items = []
deselected_items = []
if config.getoption("--anytest-output"):
# Deselect all test items which doesn't save data.
# Deselect all test items which doesn't save data.
for item in items:
if getattr(item, "hdf5_outputs", False):
selected_items.append(item)
Expand All @@ -224,9 +225,6 @@ def pytest_collection_modifyitems(items, config):
items[:] = selected_items





class AnyFile(pytest.File):
"""pytest.File subclass for AnyScript files."""

Expand Down Expand Up @@ -323,7 +321,10 @@ def __init__(self, name, id, parent, defs, paths, **kwargs):

def runtest(self):
"""Run an AnyScript test item."""
tmpdir = Path(self.config._tmpdirhandler.mktemp(self.name).strpath)

tmpdir = Path(
TempdirFactory(TempPathFactory.from_config(self.config)).mktemp(self.name)
)

with change_dir(tmpdir):
self.app = AnyPyProcess(**self.app_opts)
Expand Down

0 comments on commit 7541eca

Please sign in to comment.