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

Support usage in Jupyter notebooks #1207

Closed
ralfw opened this issue Dec 21, 2019 · 6 comments
Closed

Support usage in Jupyter notebooks #1207

ralfw opened this issue Dec 21, 2019 · 6 comments
Labels

Comments

@ralfw
Copy link

ralfw commented Dec 21, 2019

Description

When using FluentAssertions in a C# Jupyter notebook and the assertion fails, the exception is not pertaining to the actual mismatch, but regarding missing infrastructure.

Complete minimal example reproducing the issue

fluentassertions failure in jupyter notebook

Expected behavior:

The expected exception for the above example is:

Expected value to be 99, but found 1.
   at FluentAssertions.Execution.LateBoundTestFramework.Throw(String message)
   at FluentAssertions.Execution.TestFrameworkProvider.Throw(String message)
   at FluentAssertions.Execution.DefaultAssertionStrategy.HandleFailure(String message)
   ...

Actual behavior:

The actual exception is:

Unhandled Exception
Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=4.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Reference assemblies should not be loaded for execution.  They can only be loaded in the Reflection-only loader context. (0x80131058)
   at FluentAssertions.Common.AppSettingsConfigurationStore.GetSetting(String name)
   at FluentAssertions.Common.Configuration.get_ValueFormatterAssembly() in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Common\Configuration.cs:line 88
   at FluentAssertions.Common.Configuration.DetermineFormatterDetectionMode() in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Common\Configuration.cs:line 55
   at FluentAssertions.Common.Configuration.get_ValueFormatterDetectionMode() in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Common\Configuration.cs:line 40
   at FluentAssertions.Formatting.AttributeBasedFormatter.get_IsScanningEnabled() in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Formatting\AttributeBasedFormatter.cs:line 33
   at FluentAssertions.Formatting.AttributeBasedFormatter.CanHandle(Object value) in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Formatting\AttributeBasedFormatter.cs:line 28
   at FluentAssertions.Formatting.Formatter.<>c__DisplayClass7_0.<Format>b__0(IValueFormatter f) in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Formatting\Formatter.cs:line 138
   at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found)
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source, Func`2 predicate)
   at FluentAssertions.Formatting.Formatter.Format(Object value, FormattingContext context, FormatChild formatChild) in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Formatting\Formatter.cs:line 138
   at FluentAssertions.Formatting.Formatter.ToString(Object value, Boolean useLineBreaks) in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Formatting\Formatter.cs:line 97
   at FluentAssertions.Execution.MessageBuilder.<FormatArgumentPlaceholders>b__6_0(Object a) in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Execution\MessageBuilder.cs:line 91
   at System.Linq.Enumerable.SelectArrayIterator`2.ToArray()
   at FluentAssertions.Execution.MessageBuilder.FormatArgumentPlaceholders(String failureMessage, Object[] failureArgs) in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Execution\MessageBuilder.cs:line 91
   at FluentAssertions.Execution.MessageBuilder.Build(String message, Object[] messageArgs, String reason, ContextDataItems contextData, String identifier, String fallbackIdentifier) in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Execution\MessageBuilder.cs:line 40
   at FluentAssertions.Execution.AssertionScope.<>c__DisplayClass30_0.<FailWith>b__0() in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Execution\AssertionScope.cs:line 200
   at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc) in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Execution\AssertionScope.cs:line 216
   at FluentAssertions.Execution.AssertionScope.FailWith(Func`1 failReasonFunc) in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Execution\AssertionScope.cs:line 196
   at FluentAssertions.Execution.AssertionScope.FailWith(String message, Object[] args) in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Execution\AssertionScope.cs:line 238
   at FluentAssertions.Numeric.NumericAssertions`1.Be(T expected, String because, Object[] becauseArgs) in C:\projects\fluentassertions-vf06b\Src\FluentAssertions\Numeric\NumericAssertions.cs:line 51
   at Submission#7.<<Initialize>>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.CodeAnalysis.Scripting.ScriptExecutionState.RunSubmissionsAsync[TResult](ImmutableArray`1 precedingExecutors, Func`2 currentExecutor, StrongBox`1 exceptionHolderOpt, Func`2 catchExceptionOpt, CancellationToken cancellationToken)

The behavior does not change if #r "nuget:System.Configuration.ConfigurationManager" is added to the cell before loading FluentAssertions.

Versions

  • Which version of Fluent Assertions are you using? The latest version downloaded by the #r statement.
  • Which .NET runtime and version are you targeting? The latest .NET Core version installed into the Jupyter Docker image.
@dennisdoomen
Copy link
Member

The latest version downloaded by the #r statement.
The latest .NET Core version installed into the Jupyter Docker image.

Can you please share some more specifics. We have no experience with Jupyter notebooks.

@ralfw
Copy link
Author

ralfw commented Dec 25, 2019

You can play around with the above scenario in this published notebook.

Or read more about C# and Jupyter Notebooks here or here.

In short: Jupyter Notebooks run C# scripts in the web browser "embedded" between markdown text. A great tool for prototyping and documentation/explanation.

With display even structured data can easily displayed. But I'd like to also include tests in notebooks to show at a glance that some stretch of code is correct.

@jnyrup jnyrup added the bug label Dec 25, 2019
@jnyrup jnyrup added this to the 6.0 milestone Dec 25, 2019
@jnyrup
Copy link
Member

jnyrup commented Dec 25, 2019

@ralfw Thanks for reporting this bug!

Until this is fixed, here's a dirty workaround that makes your provided Jupyter Notebook work as expected.

using FluentAssertions.Common;
Configuration.Current.ValueFormatterDetectionMode = ValueFormatterDetectionMode.Disabled;
Configuration.Current.TestFrameworkName = "fallback";

@ralfw
Copy link
Author

ralfw commented Dec 25, 2019

Thanks for the workaround! I can live with that for now. But a solution to the root problem would be nice, too, of course.😉

jnyrup added a commit to jnyrup/fluentassertions that referenced this issue Dec 29, 2019
Some platforms throws reflection exceptions when trying to use `ConfigurationManager`.
This does not fix the underlying problem of not being unable to use `ConfigurationManager`, but returns `null` instead of an exception.

Relates to fluentassertions#1207 and fluentassertions#1152
jnyrup added a commit to jnyrup/fluentassertions that referenced this issue Dec 29, 2019
Some platforms throws reflection exceptions when trying to use `ConfigurationManager`.
This does not fix the underlying problem of not being unable to use `ConfigurationManager`, but returns `null` instead of an exception.

Relates to fluentassertions#1207 and fluentassertions#1151
jnyrup added a commit to jnyrup/fluentassertions that referenced this issue Dec 29, 2019
Some platforms throws reflection exceptions when trying to use `ConfigurationManager`.
This does not fix the underlying problem of not being unable to use `ConfigurationManager`, but returns `null` instead of an exception.

Relates to fluentassertions#1207 and fluentassertions#1151
jnyrup added a commit to jnyrup/fluentassertions that referenced this issue Dec 29, 2019
Some platforms throws reflection exceptions when trying to use `ConfigurationManager`.
This does not fix the underlying problem of not being unable to use `ConfigurationManager`, but returns `null` instead of an exception.

Relates to fluentassertions#1207 and fluentassertions#1151
@dennisdoomen
Copy link
Member

Can we close this now?

@jnyrup
Copy link
Member

jnyrup commented Jan 1, 2020

Yes, I'm good with the decorator approach.

@jnyrup jnyrup closed this as completed Jan 1, 2020
@jnyrup jnyrup removed this from the 6.0 milestone Jan 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants