Skip to content

Commit

Permalink
Merge pull request #389 from EnergySystemsModellingLab/fix-no-logging…
Browse files Browse the repository at this point in the history
…-for-tests

Fix: Disable logging for integration tests
  • Loading branch information
alexdewar authored Feb 14, 2025
2 parents 67ee72a + 7f49378 commit 2ce9730
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ use std::path::Path;

/// The default log level for the program.
///
/// Note that we disable logging when running tests.
const DEFAULT_LOG_LEVEL: &str = if cfg!(test) { "off" } else { "info" };
/// Used as a fallback if the user hasn't specified something else with the MUSE2_LOG_LEVEL
/// environment variable or the settings.toml file.
const DEFAULT_LOG_LEVEL: &str = "info";

/// The file name for the log file containing messages about the ordinary operation of MUSE 2.0
const LOG_INFO_FILE_NAME: &str = "muse2_info.log";
Expand Down
1 change: 1 addition & 0 deletions tests/example_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ use muse2::commands::handle_example_run_command;
/// An integration test for the `example run` command.
#[test]
fn test_handle_example_run_command() {
std::env::set_var("MUSE2_LOG_LEVEL", "off");
handle_example_run_command("simple").unwrap();
}
1 change: 1 addition & 0 deletions tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ fn get_model_dir() -> PathBuf {
/// An integration test for the `run` command.
#[test]
fn test_handle_run_command() {
std::env::set_var("MUSE2_LOG_LEVEL", "off");
handle_run_command(&get_model_dir()).unwrap();

// Second time will fail because the logging is already initialised
Expand Down

0 comments on commit 2ce9730

Please sign in to comment.