diff --git a/doc/contribute-to-core-lightning/coding-style-guidelines/writing-json-schemas.md b/doc/contribute-to-core-lightning/coding-style-guidelines/writing-json-schemas.md index 66d80c24eeee..5fad0ffd9de1 100644 --- a/doc/contribute-to-core-lightning/coding-style-guidelines/writing-json-schemas.md +++ b/doc/contribute-to-core-lightning/coding-style-guidelines/writing-json-schemas.md @@ -94,7 +94,7 @@ preventing accidental overwrites from unrelated tests. where `n` can be any number of repetitions. OR by manually running the test multiple times with: ```bash - rm -rf /tmp/ltests* && make -s && VALGRIND=0 TIMEOUT=40 TEST_DEBUG=1 GENERATE_EXAMPLES=1 pytest -vvv tests/autogenerate-rpc-examples.py + rm -rf /tmp/ltests* && make -s && VALGRIND=0 TIMEOUT=40 TEST_DEBUG=1 GENERATE_EXAMPLES=1 pytest -vvv -s tests/autogenerate-rpc-examples.py ``` - Identify changing values, and add them to `REPLACE_RESPONSE_VALUES`: @@ -117,7 +117,7 @@ environment variable with a comma-separated list of method names. Eg. `REGENERAT only regenerate examples for the `getinfo` and `connect` RPCs. 2. To regenerate specific examples, set the REGENERATE environment variable: ```bash -REGENERATE='getinfo,connect' VALGRIND=0 TIMEOUT=10 TEST_DEBUG=1 GENERATE_EXAMPLES=1 pytest -vvv tests/autogenerate-rpc-examples.py +REGENERATE='getinfo,connect' VALGRIND=0 TIMEOUT=10 TEST_DEBUG=1 GENERATE_EXAMPLES=1 pytest -vvv -s tests/autogenerate-rpc-examples.py ``` 3. Logs are saved in `tests/autogenerate-examples-status.log`, and JSON data is in `tests/autogenerate-examples.json`. 4. Run `make` after the script completes to ensure schema updates are applied in other places too, such as `...msggen/schema.json`. @@ -127,4 +127,4 @@ REGENERATE='getinfo,connect' VALGRIND=0 TIMEOUT=10 TEST_DEBUG=1 GENERATE_EXAMPLE 1. Sip whenever you have an additional comma at the end of a sequence. 2. Sip whenever you omit a comma in a sequence because you cut & paste. -3. Skull whenever you wish JSON had comments. \ No newline at end of file +3. Skull whenever you wish JSON had comments. diff --git a/tests/autogenerate-rpc-examples.py b/tests/autogenerate-rpc-examples.py index c1f76e3e45fc..1faf323f6a97 100644 --- a/tests/autogenerate-rpc-examples.py +++ b/tests/autogenerate-rpc-examples.py @@ -297,15 +297,6 @@ if os.path.exists(LOG_FILE): open(LOG_FILE, 'w').close() - -logging.basicConfig(level=logging.INFO, - format='%(asctime)s - %(levelname)s - %(message)s', - datefmt='%H:%M:%S', - handlers=[ - logging.FileHandler(LOG_FILE), - logging.StreamHandler() - ]) - logger = logging.getLogger(__name__) @@ -2035,6 +2026,19 @@ def generate_list_examples(l1, l2, l3, c12, c23_2, inv_l31, inv_l32, offer_l23, raise +@pytest.fixture(autouse=True) +def setup_logging(): + global logger + logger.setLevel(logging.DEBUG) + formatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s", "%H:%M:%S") + stream_handler = logging.StreamHandler() + stream_handler.setFormatter(formatter) + logger.addHandler(stream_handler) + file_handler = logging.FileHandler(LOG_FILE) + file_handler.setFormatter(formatter) + logger.addHandler(file_handler) + + @unittest.skipIf(not GENERATE_EXAMPLES, 'Generates examples for doc/schema/lightning-*.json files.') def test_generate_examples(node_factory, bitcoind, executor): """Re-generates examples for doc/schema/lightning-*.json files""" @@ -2055,9 +2059,9 @@ def list_all_examples(): for node in ast.walk(tree): if isinstance(node, ast.Call) and isinstance(node.func, ast.Name) and node.func.id == 'update_example': for keyword in node.keywords: - if (keyword.arg == 'method' and isinstance(keyword.value, ast.Str)): - if keyword.value.s not in methods: - methods.append(keyword.value.s) + if (keyword.arg == 'method' and isinstance(keyword.value, ast.Constant)): + if keyword.value.value not in methods: + methods.append(keyword.value.value) return methods except Exception as e: logger.error(f'Error in listing all examples: {e}') @@ -2105,5 +2109,5 @@ def list_missing_examples(): update_examples_in_schema_files() logger.info('All Done!!!') except Exception as e: - logger.error(e) + logger.error(e, exc_info=True) sys.exit(1)