Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CancelAfterAttribute + CancellationToken results in analyzer warning "no arguments are supplied by attributes" #836

Closed
fabianoliver opened this issue Jan 23, 2025 · 2 comments

Comments

@fabianoliver
Copy link

Using Nunit 4.3.2 + NUnit.Analyzers 4.6.0,

[Test, CancelAfter(123)]
public async Task some_test(CancellationToken ct)
{ /* ... */ }

results in an analyzer warning:

The test method has parameters, but no arguments are supplied by attributes

It looks like the analyzer fails to recognise that the CancellationToken is provided via CancelAfterAttribute

@mikkelbu
Copy link
Member

@fabianoliver I cannot reproduce this locally with the newest analyzers and it should be fixed by #663 (so in version 4). Also, we have a test that is quite similar in the codebase

https://github.com/nunit/nunit.analyzers/blob/b075532c1b3e24a292029d89d56e277703c13561/src/nunit.analyzers.tests/TestMethodUsage/TestMethodUsageAnalyzerTests.cs#L541:L555

[Test]
[CancelAfter(50)]
public async Task InfiniteLoopWith50msCancelAfter(CancellationToken cancellationToken)
{
    while (!cancellationToken.IsCancellationRequested)
    {
        await Task.Delay(100, cancellationToken).ConfigureAwait(false);
    }
}

My best guess is that VS (if you are running the tests with VS) has cached an old version of the NUnit Analyzers. Can you also reproduce the problem in a fresh project?

@fabianoliver
Copy link
Author

@mikkelbu Thanks for having a look.

I had bumped NUnit.Analyzers to the latest version just a day or two prior to noticing this - I could imagine that the IDE (Rider) may not have reloaded the analyzer properly or so. Have just given it another whirl after clearing caches & co and that does look better now, so probably not an NUnit issue - apologies!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants