def test_simple_profiler_with_nonexisting_log_dir(tmp_path):
    """Ensure the profiler dirpath defaults to `trainer.log_dir`and creates it when not present."""
    nonexisting_tmp_path = tmp_path / "nonexisting"

    profiler = SimpleProfiler(filename="profiler")
    assert profiler.dirpath is None

    model = BoringModel()
    trainer = Trainer(
        default_root_dir=nonexisting_tmp_path,
        max_epochs=1,
        limit_train_batches=1,
        limit_val_batches=1,
        profiler=profiler,
        logger=False,
    )
    trainer.fit(model)

    assert nonexisting_tmp_path.exists()
    assert trainer.log_dir == str(nonexisting_tmp_path)
    assert profiler.dirpath == trainer.log_dir
    assert (nonexisting_tmp_path / "fit-profiler.txt").exists()
Ensure the profiler dirpath defaults to `trainer.log_dir`and creates it when not present.
tests/tests_pytorch/profilers/test_profiler.py