(pytester: Pytester)
| 919 | |
| 920 | |
| 921 | def test_collection_logging_to_file(pytester: Pytester) -> None: |
| 922 | log_file = str(pytester.path.joinpath("pytest.log")) |
| 923 | |
| 924 | pytester.makeini( |
| 925 | """ |
| 926 | [pytest] |
| 927 | log_file={} |
| 928 | log_file_level = INFO |
| 929 | """.format( |
| 930 | log_file |
| 931 | ) |
| 932 | ) |
| 933 | |
| 934 | pytester.makepyfile( |
| 935 | """ |
| 936 | import logging |
| 937 | |
| 938 | logging.getLogger().info("Normal message") |
| 939 | |
| 940 | def test_simple(): |
| 941 | logging.getLogger().debug("debug message in test_simple") |
| 942 | logging.getLogger().info("info message in test_simple") |
| 943 | """ |
| 944 | ) |
| 945 | |
| 946 | result = pytester.runpytest() |
| 947 | |
| 948 | result.stdout.no_fnmatch_line("*--- live log collection ---*") |
| 949 | |
| 950 | assert result.ret == 0 |
| 951 | assert os.path.isfile(log_file) |
| 952 | with open(log_file, encoding="utf-8") as rfh: |
| 953 | contents = rfh.read() |
| 954 | assert "Normal message" in contents |
| 955 | assert "debug message in test_simple" not in contents |
| 956 | assert "info message in test_simple" in contents |
| 957 | |
| 958 | |
| 959 | def test_log_in_hooks(pytester: Pytester) -> None: |
nothing calls this directly
no test coverage detected