I have a function

//for testing purposes only!
pub fn some_fn(n: T::BlockNumber) {

for testing purposes only!

How to check is it a mock runtime?

something like that

let is_mock = frame_system::is_mock_runtime!

But frame_system::is_mock_runtime macros does not exist.

Please give me advise how to check is it a mock runtime or not. Thanks.

Happy New Year!🎄


1 Answer 1


Were does this function live? Is it inside a pallet?

In any case you can use Rust features to make it available only for testing like this:

// Std is never enabled in the Runtime.
// This function can only be called from testing but not from the pallet itself:
#[cfg(feature = "std")]
pub fn some_fn(n: T::BlockNumber) {
// Or you can restrict it to testing, which only works from the same crate since the
// 'test' feature does not propagate to dependencies:
pub fn some_fn(n: T::BlockNumber) {

This is being done in the the Generalized Message Queue pallet to shield its debug_info() function from accidental production use.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.