Mercurial > piecrust2
diff tests/basefs.py @ 979:45ad976712ec
tests: Big push to get the tests to pass again.
- Lots of fixes everywhere in the code.
- Try to handle debug logging in the multiprocessing worker pool when running in pytest. Not perfect, but usable for now.
- Replace all `.md` test files with `.html` since now a auto-format extension always sets the format.
- Replace `out` with `outfiles` in most places since now blog archives are added to the bake output and I don't want to add expected outputs for blog archives everywhere.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 29 Oct 2017 22:51:57 -0700 |
parents | 72f17534d58e |
children | 6350ee084273 |
line wrap: on
line diff
--- a/tests/basefs.py Sun Oct 29 22:46:41 2017 -0700 +++ b/tests/basefs.py Sun Oct 29 22:51:57 2017 -0700 @@ -1,11 +1,14 @@ import os.path import yaml from piecrust.app import PieCrust -from piecrust.main import _pre_parse_chef_args, _run_chef from piecrust.sources.base import ContentItem class TestFileSystemBase(object): + _use_chef_debug = False + _pytest_log_handler = None + _leave_mockfs = False + def __init__(self): pass @@ -99,10 +102,31 @@ def runChef(self, *args): root_dir = self.path('/kitchen') - chef_args = ['--root', root_dir] + args + chef_args = ['--root', root_dir] + if self._use_chef_debug: + chef_args += ['--debug'] + chef_args += list(args) + + import logging + from piecrust.main import ( + _make_chef_state, _recover_pre_chef_state, + _pre_parse_chef_args, _run_chef) - pre_args = _pre_parse_chef_args(chef_args) + # If py.test added a log handler, remove it because Chef will + # add its own logger. + if self._pytest_log_handler: + logging.getLogger().removeHandler( + self._pytest_log_handler) + + state = _make_chef_state() + pre_args = _pre_parse_chef_args(chef_args, state=state) exit_code = _run_chef(pre_args, chef_args) + _recover_pre_chef_state(state) + + if self._pytest_log_handler: + logging.getLogger().addHandler( + self._pytest_log_handler) + assert exit_code == 0 def getSimplePage(self, rel_path):