Mercurial > piecrust2
annotate tests/conftest.py @ 182:a54d3c0b5f4a
tests: Patch `os.path.exists` and improve patching for `open`.
You can specify additional modules for which to patch `open`.
Also, it was incorrectly updating the opened file, even when it was opened
for read only. Now it only updates the contents if the file was opened for
write, and supports appending to the end.
Last, it supports opening text files in binary mode.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 04 Jan 2015 14:55:41 -0800 |
parents | 1cd67680c38c |
children | 76c838453dbe |
rev | line source |
---|---|
86
1cd67680c38c
Ability to output debug logging to `stdout` when running unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
1 import sys |
1cd67680c38c
Ability to output debug logging to `stdout` when running unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
2 import logging |
1cd67680c38c
Ability to output debug logging to `stdout` when running unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
3 |
1cd67680c38c
Ability to output debug logging to `stdout` when running unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
4 |
1cd67680c38c
Ability to output debug logging to `stdout` when running unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
5 def pytest_runtest_setup(item): |
1cd67680c38c
Ability to output debug logging to `stdout` when running unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
6 pass |
1cd67680c38c
Ability to output debug logging to `stdout` when running unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
7 |
1cd67680c38c
Ability to output debug logging to `stdout` when running unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
8 |
1cd67680c38c
Ability to output debug logging to `stdout` when running unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
9 def pytest_addoption(parser): |
1cd67680c38c
Ability to output debug logging to `stdout` when running unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
10 parser.addoption('--log-debug', action='store_true', |
1cd67680c38c
Ability to output debug logging to `stdout` when running unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
11 help="Sets the PieCrust logger to output debug info to stdout.") |
1cd67680c38c
Ability to output debug logging to `stdout` when running unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
12 |
1cd67680c38c
Ability to output debug logging to `stdout` when running unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
13 |
1cd67680c38c
Ability to output debug logging to `stdout` when running unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
14 def pytest_configure(config): |
1cd67680c38c
Ability to output debug logging to `stdout` when running unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
15 if config.getoption('--log-debug'): |
1cd67680c38c
Ability to output debug logging to `stdout` when running unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
16 hdl = logging.StreamHandler(stream=sys.stdout) |
1cd67680c38c
Ability to output debug logging to `stdout` when running unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
17 logging.getLogger('piecrust').addHandler(hdl) |
1cd67680c38c
Ability to output debug logging to `stdout` when running unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
18 logging.getLogger('piecrust').setLevel(logging.DEBUG) |
1cd67680c38c
Ability to output debug logging to `stdout` when running unit-tests.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff
changeset
|
19 |