Skip to content

cfg(test) is not set during integration tests #84629

Open
@Timmmm

Description

@Timmmm

#[cfg(test)] is not set when running integration tests. That page says:

[Integration tests] use your library in the same way any other code would, which means they can only call functions that are part of your library’s public API.

But that sounds to me more like it's talking about pub, pub(crate) and so on.

There's an unsatisfying workaround but it would be a lot simpler if #[cfg(test)] was simply enabled for integration tests. (Here's another person tripping up on this.)

The only reason not to do that seems to be a philosophical objection to using hidden APIs in integration tests. I don't agree with that. I'm sure others don't. But even if you subscribe to that philosophy you can simply not use the #[cfg(test)] functions in your integration tests (or don't export them). The situation for people who don't subscribe to that philosophy is much more awkward.

Changing this behaviour would also fix #45599.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-libtestArea: `#[test]` / the `test` libraryC-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-testing-devexRelevant to the testing devex team (testing DX), which will review and decide on the PR/issue.

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions